Understand Sizedness in Rust
masterIn Rust, a type is sized if its size in bytes can be determined at compile-time. This allows instances of the type to be allocated on the stack and passed by value.
If a type's size cannot be determined at compile-time, it is an unsized type (also known as a DST or Dynamically-Sized Type). Unsized types cannot be placed on the stack and must be passed around by reference.
Terminology Summary
| Phrase | Meaning |
|---|---|
| sized type | Type with a known size at compile time |
| unsized type / DST | Dynamically-sized type; size not known at compile time |
| unsized coercion | Coercing a sized type into an unsized type |
| ZST | Zero-sized type; instances are 0 bytes in size |
| thin pointer | A pointer that is 1 width (e.g., pointer to a sized type) |
| fat pointer | A pointer that is 2 widths (e.g., pointer to an unsized type) |
| slice | A double-width pointer to a dynamically sized view into an array |
| trait object | A double-width pointer to data and a vtable |
| unsized struct pointer | A double-width pointer to struct data and the struct's size |