pub trait Unsize<T>where
T: ?Sized,{ }
🔬This is a nightly-only experimental API. (
unsize
#18598)Expand description
Types that can be “unsized” to a dynamically-sized type.
For example, the sized array type [i8; 2]
implements Unsize<[i8]>
and
Unsize<dyn fmt::Debug>
.
All implementations of Unsize
are provided automatically by the compiler.
Those implementations are:
- Arrays
[T; N]
implementUnsize<[T]>
. - Types implementing a trait
Trait
also implementUnsize<dyn Trait>
. - Structs
Foo<..., T, ...>
implementUnsize<Foo<..., U, ...>>
if all of these conditions are met:T: Unsize<U>
.- Only the last field of
Foo
has a type involvingT
. Bar<T>: Unsize<Bar<U>>
, whereBar<T>
stands for the actual type of that last field.
Unsize
is used along with ops::CoerceUnsized
to allow
“user-defined” containers such as Rc
to contain dynamically-sized
types. See the DST coercion RFC and the nomicon entry on coercion
for more details.