File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change 137
137
#![ feature( stmt_expr_attributes) ]
138
138
#![ feature( str_split_as_str) ]
139
139
#![ feature( str_split_inclusive_as_str) ]
140
+ #![ feature( char_indices_offset) ]
140
141
#![ feature( trait_alias) ]
141
142
#![ feature( transparent_unions) ]
142
143
#![ feature( try_blocks) ]
Original file line number Diff line number Diff line change @@ -189,6 +189,29 @@ impl<'a> CharIndices<'a> {
189
189
pub fn as_str ( & self ) -> & ' a str {
190
190
self . iter . as_str ( )
191
191
}
192
+
193
+ /// Returns the byte position of the next character, or the length
194
+ /// of the underlying string if there are no more characters.
195
+ ///
196
+ /// # Examples
197
+ ///
198
+ /// ```
199
+ /// let mut chars = "a楽".char_indices();
200
+ ///
201
+ /// assert_eq!(chars.offset(), 0);
202
+ /// assert_eq!(chars.next(), Some((0, 'a')));
203
+ ///
204
+ /// assert_eq!(chars.offset(), 1);
205
+ /// assert_eq!(chars.next(), Some((1, '楽')));
206
+ ///
207
+ /// assert_eq!(chars.offset(), 4);
208
+ /// assert_eq!(chars.next(), None);
209
+ /// ```
210
+ #[ inline]
211
+ #[ unstable( feature = "char_indices_offset" , issue = "none" ) ]
212
+ pub fn offset ( & self ) -> usize {
213
+ self . front_offset
214
+ }
192
215
}
193
216
194
217
/// An iterator over the bytes of a string slice.
You can’t perform that action at this time.
0 commit comments