Stabilize feature char_indices_offset
· rust-lang/rust@dbad758 (original) (raw)
`@@ -241,24 +241,35 @@ impl<'a> CharIndices<'a> {
`
241
241
`/// Returns the byte position of the next character, or the length
`
242
242
`/// of the underlying string if there are no more characters.
`
243
243
`///
`
``
244
`+
/// This means that, when the iterator has not been fully consumed,
`
``
245
`+
/// the returned value will match the index that will be returned
`
``
246
`` +
/// by the next call to next()
.
``
``
247
`+
///
`
244
248
`/// # Examples
`
245
249
`///
`
246
250
```` /// ```
`247`
``
`-
/// #![feature(char_indices_offset)]
`
`248`
`251`
`/// let mut chars = "a楽".char_indices();
`
`249`
`252`
`///
`
``
`253`
`` +
/// // `next()` has not been called yet, so `offset()` returns the byte
``
``
`254`
`+
/// // index of the first character of the string, which is always 0.
`
`250`
`255`
`/// assert_eq!(chars.offset(), 0);
`
``
`256`
`` +
/// // As expected, the first call to `next()` also returns 0 as index.
``
`251`
`257`
`/// assert_eq!(chars.next(), Some((0, 'a')));
`
`252`
`258`
`///
`
``
`259`
`` +
/// // `next()` has been called once, so `offset()` returns the byte index
``
``
`260`
`+
/// // of the second character ...
`
`253`
`261`
`/// assert_eq!(chars.offset(), 1);
`
``
`262`
`` +
/// // ... which matches the index returned by the next call to `next()`.
``
`254`
`263`
`/// assert_eq!(chars.next(), Some((1, '楽')));
`
`255`
`264`
`///
`
``
`265`
`` +
/// // Once the iterator has been consumed, `offset()` returns the length
``
``
`266`
`+
/// // in bytes of the string.
`
`256`
`267`
`/// assert_eq!(chars.offset(), 4);
`
`257`
`268`
`/// assert_eq!(chars.next(), None);
`
`258`
`269`
```` /// ```
259
270
`#[inline]
`
260
271
`#[must_use]
`
261
``
`-
#[unstable(feature = "char_indices_offset", issue = "83871")]
`
``
272
`+
#[stable(feature = "char_indices_offset", since = "CURRENT_RUSTC_VERSION")]
`
262
273
`pub fn offset(&self) -> usize {
`
263
274
`self.front_offset
`
264
275
`}
`