Skip to content

Commit daa62d9

Browse files
committed
Add as_str() and AsRef to string::Drain.
1 parent b4bdc07 commit daa62d9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

library/alloc/src/string.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,6 +2462,32 @@ impl Drop for Drain<'_> {
24622462
}
24632463
}
24642464

2465+
impl<'a> Drain<'a> {
2466+
/// Returns the remaining (sub)string of this iterator as a slice.
2467+
///
2468+
/// # Examples
2469+
///
2470+
/// ```
2471+
/// #![feature(string_drain_as_str)]
2472+
/// let mut s = String::from("abc");
2473+
/// let mut drain = s.drain(..);
2474+
/// assert_eq!(drain.as_str(), "abc");
2475+
/// let _ = drain.next().unwrap();
2476+
/// assert_eq!(drain.as_str(), "bc");
2477+
/// ```
2478+
#[unstable(feature = "string_drain_as_str", issue = "none")]
2479+
pub fn as_str(&self) -> &str {
2480+
self.iter.as_str()
2481+
}
2482+
}
2483+
2484+
#[unstable(feature = "string_drain_as_str", issue = "none")]
2485+
impl<'a> AsRef<str> for Drain<'a> {
2486+
fn as_ref(&self) -> &str {
2487+
self.as_str()
2488+
}
2489+
}
2490+
24652491
#[stable(feature = "drain", since = "1.6.0")]
24662492
impl Iterator for Drain<'_> {
24672493
type Item = char;

0 commit comments

Comments
 (0)