Rollup merge of #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.
This commit is contained in:
commit
f740b8a4de
1 changed files with 2 additions and 2 deletions
|
@ -323,8 +323,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 { }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue