Add as_str() and AsRef to string::Drain.

This commit is contained in:
Mara Bos 2020-09-09 17:40:15 +02:00
parent b4bdc07ff5
commit daa62d9081
1 changed files with 26 additions and 0 deletions

View File

@ -2462,6 +2462,32 @@ impl Drop for Drain<'_> {
}
}
impl<'a> Drain<'a> {
/// Returns the remaining (sub)string of this iterator as a slice.
///
/// # Examples
///
/// ```
/// #![feature(string_drain_as_str)]
/// let mut s = String::from("abc");
/// let mut drain = s.drain(..);
/// assert_eq!(drain.as_str(), "abc");
/// let _ = drain.next().unwrap();
/// assert_eq!(drain.as_str(), "bc");
/// ```
#[unstable(feature = "string_drain_as_str", issue = "none")]
pub fn as_str(&self) -> &str {
self.iter.as_str()
}
}
#[unstable(feature = "string_drain_as_str", issue = "none")]
impl<'a> AsRef<str> for Drain<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}
#[stable(feature = "drain", since = "1.6.0")]
impl Iterator for Drain<'_> {
type Item = char;