For now, this reference is a best-effort document. We strive for validity and completeness, but are not yet there. In the future, the docs and lang teams will work together to figure out how best to do this. Until then, this is a best-effort attempt. If you find something wrong or missing, file an issue or send in a pull request.

Dynamically Sized Types

Most types have a fixed size that is known at compile time and implement the trait Sized. A type with a size that is known only at run-time is called a dynamically sized type (DST) or, informally, an unsized type. Slices and trait objects are two examples of DSTs. Such types can only be used in certain cases:

  • Pointer types to DSTs are sized but have twice the size of pointers to sized types
    • Pointers to slices also store the number of elements of the slice.
    • Pointers to trait objects also store a pointer to a vtable.
  • DSTs can be provided as type arguments when a bound of ?Sized. By default any type parameter has a Sized bound.
  • Traits may be implemented for DSTs. Unlike type parametersSelf: ?Sized by default in trait definitions.
  • Structs may contain a DST as the last field, this makes the struct itself a DST.

Notably: variables, function parameters, const and static items must be Sized.