Skip to content

Commit

Permalink
Auto merge of #47036 - QuietMisdreavus:i-like-big-chars, r=frewsxcv
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 28, 2017
2 parents 06c8b38 + ac15a2e commit 77e189c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,13 +719,17 @@ impl str {
/// Remember, [`char`]s may not match your human intuition about characters:
///
/// ```
/// let 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")]
Expand Down

0 comments on commit 77e189c

Please sign in to comment.