File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -565,8 +565,8 @@ mod prim_array {}
565565///
566566/// *[See also the `std::slice` module](slice/index.html).*
567567///
568- /// Slices are a view into a block of memory represented as a pointer and a
569- /// length.
568+ /// A slice is any pointer/reference to a block of memory. They are represented
569+ /// as a regular pointer and a length.
570570///
571571/// ```
572572/// // slicing a Vec
@@ -587,6 +587,19 @@ mod prim_array {}
587587/// x[1] = 7;
588588/// assert_eq!(x, &[1, 7, 3]);
589589/// ```
590+ ///
591+ /// As slices store the length of the sequence they refer to, they have twice
592+ /// the size of pointers to [`Sized`](marker/trait.Sized.html) types.
593+ /// Also see the reference on
594+ /// [dynamically sized types](../reference/dynamically-sized-types.html)
595+ ///
596+ /// ```
597+ /// let pointer_size = std::mem::size_of::<&u8>();
598+ /// assert_eq!(2 * pointer_size, std::mem::size_of::<&[u8]>());
599+ /// assert_eq!(2 * pointer_size, std::mem::size_of::<*const [u8]>());
600+ /// assert_eq!(2 * pointer_size, std::mem::size_of::<Box<[u8]>>());
601+ /// assert_eq!(2 * pointer_size, std::mem::size_of::<Rc<[u8]>>());
602+ /// ```
590603#[ stable( feature = "rust1" , since = "1.0.0" ) ]
591604mod prim_slice { }
592605
You can’t perform that action at this time.
0 commit comments