Skip to content

Commit ac15a2e

Browse files
update char_indices example to highlight big chars
1 parent eff3de0 commit ac15a2e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/liballoc/str.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -719,13 +719,17 @@ impl str {
719719
/// Remember, [`char`]s may not match your human intuition about characters:
720720
///
721721
/// ```
722-
/// let y = "";
722+
/// let yes = "y̆es";
723723
///
724-
/// let mut char_indices = y.char_indices();
724+
/// let mut char_indices = yes.char_indices();
725725
///
726726
/// assert_eq!(Some((0, 'y')), char_indices.next()); // not (0, 'y̆')
727727
/// assert_eq!(Some((1, '\u{0306}')), char_indices.next());
728728
///
729+
/// // note the 3 here - the last character took up two bytes
730+
/// assert_eq!(Some((3, 'e')), char_indices.next());
731+
/// assert_eq!(Some((4, 's')), char_indices.next());
732+
///
729733
/// assert_eq!(None, char_indices.next());
730734
/// ```
731735
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)