Skip to content

Commit 0f6e274

Browse files
authored
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.
1 parent ef97813 commit 0f6e274

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/libstd/primitive_docs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ mod prim_never { }
322322
/// let s = String::from("love: ❤️");
323323
/// let v: Vec<char> = s.chars().collect();
324324
///
325-
/// assert_eq!(12, s.len() * std::mem::size_of::<u8>());
326-
/// assert_eq!(32, v.len() * std::mem::size_of::<char>());
325+
/// assert_eq!(12, std::mem::size_of_val(&s[..]));
326+
/// assert_eq!(32, std::mem::size_of_val(&v[..]));
327327
/// ```
328328
#[stable(feature = "rust1", since = "1.0.0")]
329329
mod prim_char { }

0 commit comments

Comments
 (0)