|
1 | 1 | # Dynamically Sized Types
|
2 | 2 |
|
| 3 | +r[dynamic-sized] |
| 4 | + |
| 5 | +r[dynamic-sized.intro] |
3 | 6 | Most types have a fixed size that is known at compile time and implement the
|
4 | 7 | trait [`Sized`][sized]. A type with a size that is known only at run-time is
|
5 | 8 | called a _dynamically sized type_ (_DST_) or, informally, an unsized type.
|
6 | 9 | [Slices] and [trait objects] are two examples of <abbr title="dynamically sized
|
7 |
| -types">DSTs</abbr>. Such types can only be used in certain cases: |
| 10 | +types">DSTs</abbr>. |
| 11 | + |
| 12 | +r[dynamic-sized.restriction] |
| 13 | +Such types can only be used in certain cases: |
8 | 14 |
|
| 15 | +r[dynamic-sized.pointer-types] |
9 | 16 | * [Pointer types] to <abbr title="dynamically sized types">DSTs</abbr> are
|
10 | 17 | sized but have twice the size of pointers to sized types
|
11 | 18 | * Pointers to slices also store the number of elements of the slice.
|
12 | 19 | * Pointers to trait objects also store a pointer to a vtable.
|
| 20 | + |
| 21 | +r[dynamic-sized.question-sized] |
13 | 22 | * <abbr title="dynamically sized types">DSTs</abbr> can be provided as
|
14 | 23 | type arguments to generic type parameters having the special `?Sized` bound.
|
15 | 24 | They can also be used for associated type definitions when the corresponding associated type declaration has a `?Sized` bound.
|
16 | 25 | By default, any type parameter or associated type has a `Sized` bound, unless it is relaxed using `?Sized`.
|
| 26 | + |
| 27 | +r[dynamic-sized.trait-impl] |
17 | 28 | * Traits may be implemented for <abbr title="dynamically sized
|
18 | 29 | types">DSTs</abbr>.
|
19 | 30 | Unlike with generic type parameters, `Self: ?Sized` is the default in trait definitions.
|
| 31 | + |
| 32 | +r[dynamic-sized.struct-field] |
20 | 33 | * Structs may contain a <abbr title="dynamically sized type">DST</abbr> as the
|
21 | 34 | last field; this makes the struct itself a
|
22 | 35 | <abbr title="dynamically sized type">DST</abbr>.
|
|
0 commit comments