Skip to content

Commit a55ab85

Browse files
committed
Stabilize feature char_indices_offset
1 parent ebe99f3 commit a55ab85

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Diff for: core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
#![cfg_attr(bootstrap, feature(offset_of_nested))]
111111
#![feature(array_ptr_get)]
112112
#![feature(asm_experimental_arch)]
113-
#![feature(char_indices_offset)]
114113
#![feature(const_align_of_val)]
115114
#![feature(const_align_of_val_raw)]
116115
#![feature(const_align_offset)]

Diff for: core/src/str/iter.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,35 @@ impl<'a> CharIndices<'a> {
241241
/// Returns the byte position of the next character, or the length
242242
/// of the underlying string if there are no more characters.
243243
///
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()`](Self::next).
247+
///
244248
/// # Examples
245249
///
246250
/// ```
247-
/// #![feature(char_indices_offset)]
248251
/// let mut chars = "a楽".char_indices();
249252
///
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.
250255
/// assert_eq!(chars.offset(), 0);
256+
/// // As expected, the first call to `next()` also returns 0 as index.
251257
/// assert_eq!(chars.next(), Some((0, 'a')));
252258
///
259+
/// // `next()` has been called once, so `offset()` returns the byte index
260+
/// // of the second character ...
253261
/// assert_eq!(chars.offset(), 1);
262+
/// // ... which matches the index returned by the next call to `next()`.
254263
/// assert_eq!(chars.next(), Some((1, '楽')));
255264
///
265+
/// // Once the iterator has been consumed, `offset()` returns the length
266+
/// // in bytes of the string.
256267
/// assert_eq!(chars.offset(), 4);
257268
/// assert_eq!(chars.next(), None);
258269
/// ```
259270
#[inline]
260271
#[must_use]
261-
#[unstable(feature = "char_indices_offset", issue = "83871")]
272+
#[stable(feature = "char_indices_offset", since = "CURRENT_RUSTC_VERSION")]
262273
pub fn offset(&self) -> usize {
263274
self.front_offset
264275
}

0 commit comments

Comments
 (0)