Skip to content

Commit 9687c02

Browse files
authored
Rollup merge of rust-lang#55247 - peterjoel:peterjoel-prim-char-doc-example, r=joshtriplett
Clarified code example in char primitive doc 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 elements in the slice by the item size. This change demonstrates the idea more straightforwardly, without needing a calculation, by just comparing the size of the slices.
2 parents 9f33d7e + 0f6e274 commit 9687c02

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
@@ -323,8 +323,8 @@ mod prim_never { }
323323
/// let s = String::from("love: ❤️");
324324
/// let v: Vec<char> = s.chars().collect();
325325
///
326-
/// assert_eq!(12, s.len() * std::mem::size_of::<u8>());
327-
/// assert_eq!(32, v.len() * std::mem::size_of::<char>());
326+
/// assert_eq!(12, std::mem::size_of_val(&s[..]));
327+
/// assert_eq!(32, std::mem::size_of_val(&v[..]));
328328
/// ```
329329
#[stable(feature = "rust1", since = "1.0.0")]
330330
mod prim_char { }

0 commit comments

Comments
 (0)