Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/liballoc/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,16 +1402,21 @@ impl String {
&mut self.vec
}

/// Returns the length of this `String`, in bytes.
/// Returns the length of this `String`, in bytes, not [`char`]s or
/// graphemes. In other words, it may not be what a human considers the
/// length of the string.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// let a = String::from("foo");
///
/// assert_eq!(a.len(), 3);
///
/// let fancy_f = String::from("ƒoo");
/// assert_eq!(fancy_f.len(), 4);
/// assert_eq!(fancy_f.chars().count(), 3);
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2085,8 +2085,8 @@ impl str {
/// let len = "foo".len();
/// assert_eq!(3, len);
///
/// let len = "ƒoo".len(); // fancy f!
/// assert_eq!(4, len);
/// assert_eq!("ƒoo".len(), 4); // fancy f!
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the rust convention to do assert_eq!(expected, actual)? or assert_eq!(actual, expected)?

it looks like String is doing one but str is doing the other

/// assert_eq!("ƒoo".chars().count(), 3);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[inline]
Expand Down