Trait std::marker::Unsize
pub trait Unsize<T> where T: ?Sized, { }
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.
Implementors
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/marker/trait.Unsize.html