Hi Rustaceans,
I'm sorry if this isn't the appropriate forum for a question on the design of an unstable feature.
I was trying out the ptr_metadata
feature, and noticed that this code doesn't compile:
use std::{any::Any, ptr::Pointee};
fn unsized_metadata<T: ?Sized + Any>(
x: &T,
) -> <dyn Any as Pointee>::Metadata {
std::ptr::metadata::<dyn Any>(x)
}
This has the following error:
error[E0277]: the size for values of type `T` cannot be known at compilation time
...
note: required for the cast from `T` to the object type `dyn Any`
Seeing as std::ptr::metadata(..)
takes ?Sized
and there exists a metadata type DynMetadata<Dyn: ?Sized>
, it seems like there should be a way to get the DynMetadata
from an unsized reference. I'm not sure of any other way to get an instance of that metadata type.
Am I missing something?