@@ -103,26 +103,31 @@ mod prim_bool { }
103
103
/// [`String`]: string/struct.String.html
104
104
///
105
105
/// As always, remember that a human intuition for 'character' may not map to
106
- /// Unicode's definitions. For example, emoji symbols such as '❤️' can be more
107
- /// than one Unicode code point; this ❤️ in particular is two:
106
+ /// Unicode's definitions. For example, despite looking similar, the 'é'
107
+ /// character is one Unicode code point while 'é' is two Unicode code points :
108
108
///
109
109
/// ```
110
- /// let s = String::from("❤️");
110
+ /// let mut chars = "é".chars();
111
+ /// // U+00e9: 'latin small letter e with acute'
112
+ /// assert_eq!(Some('\u{00e9}'), chars.next());
113
+ /// assert_eq!(None, chars.next());
111
114
///
112
- /// // we get two chars out of a single ❤️
113
- /// let mut iter = s.chars();
114
- /// assert_eq!(Some('\u{2764}'), iter.next());
115
- /// assert_eq!(Some('\u{fe0f}'), iter.next());
116
- /// assert_eq!(None, iter.next());
115
+ /// let mut chars = "é".chars();
116
+ /// // U+0065: 'latin small letter e'
117
+ /// assert_eq!(Some('\u{0065}'), chars.next());
118
+ /// // U+0301: 'combining acute accent'
119
+ /// assert_eq!(Some('\u{0301}'), chars.next());
120
+ /// assert_eq!(None, chars.next());
117
121
/// ```
118
122
///
119
- /// This means it won't fit into a `char`. Trying to create a literal with
120
- /// `let heart = '❤️';` gives an error:
123
+ /// This means that the contents of the first string above _will_ fit into a
124
+ /// `char` while the contents of the second string _will not_. Trying to create
125
+ /// a `char` literal with the contents of the second string gives an error:
121
126
///
122
127
/// ```text
123
- /// error: character literal may only contain one codepoint: '❤
124
- /// let heart = '❤️ ';
125
- /// ^~
128
+ /// error: character literal may only contain one codepoint: 'é'
129
+ /// let c = 'é ';
130
+ /// ^^^^
126
131
/// ```
127
132
///
128
133
/// Another implication of the 4-byte fixed size of a `char` is that
0 commit comments