about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorPietro Albini <pietro@pietroalbini.org>2019-11-05 09:49:56 +0100
committerGitHub <noreply@github.com>2019-11-05 09:49:56 +0100
commitd32a262ab8ec6d81f443b5d73b549361221c8d4e (patch)
tree5345afd55cfb64995e9cf97a2cd3bca5aa38096d /src/liballoc
parentc25975d3277a6941bd0b2ed4f46a9cc6a8540d80 (diff)
parentd9ec5fa88ca0c082aa2089b372e7981f9d514e82 (diff)
downloadrust-d32a262ab8ec6d81f443b5d73b549361221c8d4e.tar.gz
rust-d32a262ab8ec6d81f443b5d73b549361221c8d4e.zip
Rollup merge of #66038 - jdxcode:char-len, r=alexcrichton
doc(str): show example of chars().count() under len()

the docs are great at explaining that .len() isn't like in other
languages but stops short of explaining how to get the character length.
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/string.rs9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs
index d9927c642b2..0e5746d0d9d 100644
--- a/src/liballoc/string.rs
+++ b/src/liballoc/string.rs
@@ -1402,7 +1402,9 @@ 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
     ///
@@ -1410,8 +1412,11 @@ impl String {
     ///
     /// ```
     /// 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")]