diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2020-09-09 17:40:15 +0200 |
|---|---|---|
| committer | Mara Bos <m-ou.se@m-ou.se> | 2020-09-09 17:50:55 +0200 |
| commit | daa62d9081bfeeb0f438f88eb69082c227a5c221 (patch) | |
| tree | 2172c51f88d633c1769cbe22df79404116135be9 /library/alloc/src/string.rs | |
| parent | b4bdc07ff5a70175dbcdff7331c557245ddb012f (diff) | |
| download | rust-daa62d9081bfeeb0f438f88eb69082c227a5c221.tar.gz rust-daa62d9081bfeeb0f438f88eb69082c227a5c221.zip | |
Add as_str() and AsRef to string::Drain.
Diffstat (limited to 'library/alloc/src/string.rs')
| -rw-r--r-- | library/alloc/src/string.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index e1724bf3c9a..d27dd9c9340 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -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; |
