Skip to content

Commit

Permalink
Stabilize feature char_indices_offset
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardosm committed Aug 19, 2024
1 parent ebe99f3 commit a55ab85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
1 change: 0 additions & 1 deletion core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
#![cfg_attr(bootstrap, feature(offset_of_nested))]
#![feature(array_ptr_get)]
#![feature(asm_experimental_arch)]
#![feature(char_indices_offset)]
#![feature(const_align_of_val)]
#![feature(const_align_of_val_raw)]
#![feature(const_align_offset)]
Expand Down
15 changes: 13 additions & 2 deletions core/src/str/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,24 +241,35 @@ impl<'a> CharIndices<'a> {
/// Returns the byte position of the next character, or the length
/// of the underlying string if there are no more characters.
///
/// This means that, when the iterator has not been fully consumed,
/// the returned value will match the index that will be returned
/// by the next call to [`next()`](Self::next).
///
/// # Examples
///
/// ```
/// #![feature(char_indices_offset)]
/// let mut chars = "a楽".char_indices();
///
/// // `next()` has not been called yet, so `offset()` returns the byte
/// // index of the first character of the string, which is always 0.
/// assert_eq!(chars.offset(), 0);
/// // As expected, the first call to `next()` also returns 0 as index.
/// assert_eq!(chars.next(), Some((0, 'a')));
///
/// // `next()` has been called once, so `offset()` returns the byte index
/// // of the second character ...
/// assert_eq!(chars.offset(), 1);
/// // ... which matches the index returned by the next call to `next()`.
/// assert_eq!(chars.next(), Some((1, '楽')));
///
/// // Once the iterator has been consumed, `offset()` returns the length
/// // in bytes of the string.
/// assert_eq!(chars.offset(), 4);
/// assert_eq!(chars.next(), None);
/// ```
#[inline]
#[must_use]
#[unstable(feature = "char_indices_offset", issue = "83871")]
#[stable(feature = "char_indices_offset", since = "CURRENT_RUSTC_VERSION")]
pub fn offset(&self) -> usize {
self.front_offset
}
Expand Down

0 comments on commit a55ab85

Please sign in to comment.