diff options
| author | Yuki Okushi <yuki.okushi@huawei.com> | 2021-07-04 14:23:43 +0900 |
|---|---|---|
| committer | Yuki Okushi <yuki.okushi@huawei.com> | 2021-07-04 14:23:43 +0900 |
| commit | ab86df0ce9727eec35ccbb0142d1398239351e63 (patch) | |
| tree | 631312ce572444bd538966bbef0b2f05abff1acc /library/alloc/src/string.rs | |
| parent | 154071194641d8db6c056b0d83dd0d071f9f6758 (diff) | |
| download | rust-ab86df0ce9727eec35ccbb0142d1398239351e63.tar.gz rust-ab86df0ce9727eec35ccbb0142d1398239351e63.zip | |
Stabilize `string_drain_as_str`
Diffstat (limited to 'library/alloc/src/string.rs')
| -rw-r--r-- | library/alloc/src/string.rs | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index a34f530762d..d0cf6244756 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -2769,33 +2769,31 @@ impl<'a> Drain<'a> { /// # 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 = "76905")] // Note: uncomment AsRef impls below when stabilizing. + #[stable(feature = "string_drain_as_str", since = "1.55.0")] pub fn as_str(&self) -> &str { self.iter.as_str() } } -// Uncomment when stabilizing `string_drain_as_str`. -// #[unstable(feature = "string_drain_as_str", issue = "76905")] -// impl<'a> AsRef<str> for Drain<'a> { -// fn as_ref(&self) -> &str { -// self.as_str() -// } -// } -// -// #[unstable(feature = "string_drain_as_str", issue = "76905")] -// impl<'a> AsRef<[u8]> for Drain<'a> { -// fn as_ref(&self) -> &[u8] { -// self.as_str().as_bytes() -// } -// } +#[stable(feature = "string_drain_as_str", since = "1.55.0")] +impl<'a> AsRef<str> for Drain<'a> { + fn as_ref(&self) -> &str { + self.as_str() + } +} + +#[stable(feature = "string_drain_as_str", since = "1.55.0")] +impl<'a> AsRef<[u8]> for Drain<'a> { + fn as_ref(&self) -> &[u8] { + self.as_str().as_bytes() + } +} #[stable(feature = "drain", since = "1.6.0")] impl Iterator for Drain<'_> { |
