diff options
| author | bors <bors@rust-lang.org> | 2017-12-28 19:06:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-28 19:06:39 +0000 |
| commit | 77e189cd79ce98cf8d39082157445db54696f316 (patch) | |
| tree | 6614b3ec06d87d557a7cf865a04b8e72a30ea283 /src/liballoc | |
| parent | 06c8b385d1d51c1cee4fb8c463028e0e6fafeb4e (diff) | |
| parent | ac15a2e5a291138fa06f1589aaa1f350e7894843 (diff) | |
| download | rust-77e189cd79ce98cf8d39082157445db54696f316.tar.gz rust-77e189cd79ce98cf8d39082157445db54696f316.zip | |
Auto merge of #47036 - QuietMisdreavus:i-like-big-chars, r=frewsxcv
update char_indices example to highlight big chars There was a comment today in IRC where someone thought `char_indices()` and `chars().enumerate()` were equivalent, so i wanted to put an example in the docs where that wasn't true. r? @rust-lang/docs
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/str.rs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index 7fa872f4ded..a00e3d17dd0 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -719,13 +719,17 @@ impl str { /// Remember, [`char`]s may not match your human intuition about characters: /// /// ``` - /// let y = "y̆"; + /// let yes = "y̆es"; /// - /// let mut char_indices = y.char_indices(); + /// let mut char_indices = yes.char_indices(); /// /// assert_eq!(Some((0, 'y')), char_indices.next()); // not (0, 'y̆') /// assert_eq!(Some((1, '\u{0306}')), char_indices.next()); /// + /// // note the 3 here - the last character took up two bytes + /// assert_eq!(Some((3, 'e')), char_indices.next()); + /// assert_eq!(Some((4, 's')), char_indices.next()); + /// /// assert_eq!(None, char_indices.next()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] |
