about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Hall <peterjoel@gmail.com>2018-10-21 18:53:09 +0100
committerGitHub <noreply@github.com>2018-10-21 18:53:09 +0100
commit0f6e2741f692add6d1995b630e2073d18aa2b2ba (patch)
tree2c193d8a68451c928eecdbf71e05eafc61139439
parentef9781358daa0a70bdaf11c9f792210ea30dd396 (diff)
downloadrust-0f6e2741f692add6d1995b630e2073d18aa2b2ba.tar.gz
rust-0f6e2741f692add6d1995b630e2073d18aa2b2ba.zip
Clarified code example
The example was not as clear as it could be because it was making an assumption about the structure of the data in order to multiply the number of collection elements by the item size. This change demonstrates the idea more straightforwardly, without the calculation.
-rw-r--r--src/libstd/primitive_docs.rs4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libstd/primitive_docs.rs b/src/libstd/primitive_docs.rs
index 7074928eaf6..79ccd593914 100644
--- a/src/libstd/primitive_docs.rs
+++ b/src/libstd/primitive_docs.rs
@@ -322,8 +322,8 @@ mod prim_never { }
 /// let s = String::from("love: ❤️");
 /// let v: Vec<char> = s.chars().collect();
 ///
-/// assert_eq!(12, s.len() * std::mem::size_of::<u8>());
-/// assert_eq!(32, v.len() * std::mem::size_of::<char>());
+/// assert_eq!(12, std::mem::size_of_val(&s[..]));
+/// assert_eq!(32, std::mem::size_of_val(&v[..]));
 /// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 mod prim_char { }