Skip to content

Commit 77e189c

Browse files
committed
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
2 parents 06c8b38 + ac15a2e commit 77e189c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/liballoc/str.rs

+6-2
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)