Skip to content

Commit

Permalink
Auto merge of #27900 - SimonSapin:Chars_as_str, r=alexcrichton
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Aug 28, 2015
2 parents 5d955e1 + e33650c commit 3c100de
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,18 @@ impl<'a> DoubleEndedIterator for Chars<'a> {
}
}

impl<'a> Chars<'a> {
/// View the underlying data as a subslice of the original data.
///
/// This has the same lifetime as the original slice, and so the
/// iterator can continue to be used while this exists.
#[unstable(feature = "iter_to_slice", issue = "27775")]
#[inline]
pub fn as_str(&self) -> &'a str {
unsafe { from_utf8_unchecked(self.iter.as_slice()) }
}
}

/// Iterator for a string's characters and their byte offsets.
#[derive(Clone)]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -339,6 +351,18 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> {
}
}

impl<'a> CharIndices<'a> {
/// View the underlying data as a subslice of the original data.
///
/// This has the same lifetime as the original slice, and so the
/// iterator can continue to be used while this exists.
#[unstable(feature = "iter_to_slice", issue = "27775")]
#[inline]
pub fn as_str(&self) -> &'a str {
self.iter.as_str()
}
}

/// External iterator for a string's bytes.
/// Use with the `std::iter` module.
///
Expand Down

0 comments on commit 3c100de

Please sign in to comment.