Boxed types

That's the trait Sized, but what does ?Sized mean? The ? flags the relevant trait as optional. So, a box is a type in Rust parameterized over some other type T which may or may not have a size. A box is a kind of a pointer to heap allocated storage. Let's look into its implementation further. What of Unique<T>? This type is a signal to the Rust compiler that some *mut T is non-null and that the unique is the sole owner of T, even though T was allocated outside the Unique. Unique is defined like so:

pub struct Unique<T: ?Sized> {
    pointer: NonZero<*const T>,
    // NOTE: this marker has no consequences for variance, but is    // necessary for dropck to understand that we logically     // own a `T`.
    _marker: PhantomData<T>,
}

NonZero<T> is ...

Get Hands-On Concurrency with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.