From e6c83dd57b920d2069797736ae0a1c9fe14a97cb Mon Sep 17 00:00:00 2001 From: Leon Matthes Date: Sat, 1 Aug 2020 22:42:07 +0200 Subject: [PATCH 1/4] Document that slice means pointer to a sequence Also document that slices are twice as large as pointers to Sized types --- library/std/src/primitive_docs.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index 86de509e80a10..0fde4245ab514 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -565,8 +565,8 @@ mod prim_array {} /// /// *[See also the `std::slice` module](slice/index.html).* /// -/// Slices are a view into a block of memory represented as a pointer and a -/// length. +/// A slice is any pointer/reference to a block of memory. They are represented +/// as a regular pointer and a length. /// /// ``` /// // slicing a Vec @@ -587,6 +587,19 @@ mod prim_array {} /// x[1] = 7; /// assert_eq!(x, &[1, 7, 3]); /// ``` +/// +/// As slices store the length of the sequence they refer to, they have twice +/// the size of pointers to [`Sized`](marker/trait.Sized.html) types. +/// Also see the reference on +/// [dynamically sized types](../reference/dynamically-sized-types.html) +/// +/// ``` +/// let pointer_size = std::mem::size_of::<&u8>(); +/// assert_eq!(2 * pointer_size, std::mem::size_of::<&[u8]>()); +/// assert_eq!(2 * pointer_size, std::mem::size_of::<*const [u8]>()); +/// assert_eq!(2 * pointer_size, std::mem::size_of::>()); +/// assert_eq!(2 * pointer_size, std::mem::size_of::>()); +/// ``` #[stable(feature = "rust1", since = "1.0.0")] mod prim_slice {} From a9af93beebe183d716c0e7313ff8a0fb79b27b6b Mon Sep 17 00:00:00 2001 From: Leon Matthes Date: Sat, 1 Aug 2020 22:48:39 +0200 Subject: [PATCH 2/4] Add missing period --- library/std/src/primitive_docs.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index 0fde4245ab514..cbe269557ea60 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -591,7 +591,7 @@ mod prim_array {} /// As slices store the length of the sequence they refer to, they have twice /// the size of pointers to [`Sized`](marker/trait.Sized.html) types. /// Also see the reference on -/// [dynamically sized types](../reference/dynamically-sized-types.html) +/// [dynamically sized types](../reference/dynamically-sized-types.html). /// /// ``` /// let pointer_size = std::mem::size_of::<&u8>(); From 41d3e1cf738b6bfe1c7f85ad09b2adea9c8744e8 Mon Sep 17 00:00:00 2001 From: Leon Matthes Date: Sat, 1 Aug 2020 23:51:55 +0200 Subject: [PATCH 3/4] Add missing import to Rc --- library/std/src/primitive_docs.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index cbe269557ea60..fb62c3c63ca58 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -594,6 +594,7 @@ mod prim_array {} /// [dynamically sized types](../reference/dynamically-sized-types.html). /// /// ``` +/// # use std::rc::Rc; /// let pointer_size = std::mem::size_of::<&u8>(); /// assert_eq!(2 * pointer_size, std::mem::size_of::<&[u8]>()); /// assert_eq!(2 * pointer_size, std::mem::size_of::<*const [u8]>()); From cf76256b83d7ccbf1d673c4bcb3ad0d1bd904315 Mon Sep 17 00:00:00 2001 From: Leon Matthes Date: Sun, 23 Aug 2020 16:02:22 +0200 Subject: [PATCH 4/4] Revert changed paragraph about slice definition. This reverts part of commit e6c83dd57b920d2069797736ae0a1c9fe14a97cb. As requested by @steveklabnik . --- library/std/src/primitive_docs.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/std/src/primitive_docs.rs b/library/std/src/primitive_docs.rs index fb62c3c63ca58..03eb3dd2fe61b 100644 --- a/library/std/src/primitive_docs.rs +++ b/library/std/src/primitive_docs.rs @@ -565,8 +565,8 @@ mod prim_array {} /// /// *[See also the `std::slice` module](slice/index.html).* /// -/// A slice is any pointer/reference to a block of memory. They are represented -/// as a regular pointer and a length. +/// Slices are a view into a block of memory represented as a pointer and a +/// length. /// /// ``` /// // slicing a Vec