Trait std::marker::Unsize[][src]

pub trait Unsize<T> where
    T: ?Sized
{ }
🔬 This is a nightly-only experimental API. (unsize #27732)
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] implement Unsize<[T]>.
  • Types implementing a trait Trait also implement Unsize<dyn Trait>.
  • Structs Foo<..., T, ...> implement Unsize<Foo<..., U, ...>> if all of these conditions are met:
    • T: Unsize<U>.
    • Only the last field of Foo has a type involving T.
    • Bar<T>: Unsize<Bar<U>>, where Bar<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