Rust Sized, ?Sized, and unsized

Examining the Sized trait

The Sized trait is often elided, but when explicitly added it asserts that the type has a size known at compile time. This can be useful when abstracting over many types that don't necessarily even share a common trait, such as in an HList.

pub trait HList: Sized {}

pub struct HNil;
impl HList for HNil {}

pub struct HCons<H,T> {
   pub head: H,
   pub tail: T,
}
impl <H,T: HList> HList for HCons<H,T> {}

When to use the ?Sized trait

The ?Sized trait indicates to the compiler that the type does not have a size known at compile-time. Variants of this trait have apparently been available to the internal compiler, but now it has been stabilized and made available for general development.

struct Cell<T: ?Sized> {
   pub block: T
}

What is the unsized keyword

The unsized keyword was a proposed syntax for indicating that a compile-time size is not known. It was instead replaced with the ?Sized syntax and is entirely redundant.