File tree 1 file changed +15
-2
lines changed
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -565,8 +565,8 @@ mod prim_array {}
565
565
///
566
566
/// *[See also the `std::slice` module](slice/index.html).*
567
567
///
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.
570
570
///
571
571
/// ```
572
572
/// // slicing a Vec
@@ -587,6 +587,19 @@ mod prim_array {}
587
587
/// x[1] = 7;
588
588
/// assert_eq!(x, &[1, 7, 3]);
589
589
/// ```
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
+ /// ```
590
603
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
591
604
mod prim_slice { }
592
605
You can’t perform that action at this time.
0 commit comments