diff --git a/src/dynamically-sized-types.md b/src/dynamically-sized-types.md index 28c398b7d..7434cbb77 100644 --- a/src/dynamically-sized-types.md +++ b/src/dynamically-sized-types.md @@ -5,7 +5,7 @@ r[dynamic-sized.intro] Most types have a fixed size that is known at compile time and implement the trait [`Sized`][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. r[dynamic-sized.restriction] @@ -14,7 +14,7 @@ Such types can only be used in certain cases: r[dynamic-sized.pointer-types] * [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 slices and `str` also store the number of elements of the slice. * Pointers to trait objects also store a pointer to a vtable. r[dynamic-sized.question-sized] @@ -38,6 +38,7 @@ r[dynamic-sized.struct-field] [sized]: special-types-and-traits.md#sized [Slices]: types/slice.md +[str]: types/textual.md [trait objects]: types/trait-object.md [Pointer types]: types/pointer.md [Variables]: variables.md diff --git a/src/type-layout.md b/src/type-layout.md index cefa1dc11..d05d2cfc5 100644 --- a/src/type-layout.md +++ b/src/type-layout.md @@ -110,6 +110,7 @@ r[layout.str] ## `str` Layout String slices are a UTF-8 representation of characters that have the same layout as slices of type `[u8]`. +A reference `&str` has the same layout as a reference `&[u8]`. r[layout.tuple] ## Tuple Layout diff --git a/src/types/textual.md b/src/types/textual.md index a6ad38ffc..32722e720 100644 --- a/src/types/textual.md +++ b/src/types/textual.md @@ -23,7 +23,8 @@ is valid UTF-8. Calling a `str` method with a non-UTF-8 buffer can cause r[type.text.str-unsized] Since `str` is a [dynamically sized type], it can only be instantiated through a -pointer type, such as `&str`. +pointer type, such as `&str`. The layout of `&str` is the same as the layout of +`&[u8]`. r[type.text.layout] ## Layout and bit validity