Skip to content

Commit

Permalink
Rollup merge of #86858 - JohnTitor:stabilize-string-drain-as-str, r=M…
Browse files Browse the repository at this point in the history
…ark-Simulacrum

Stabilize `string_drain_as_str`

Closes #76905, FCP is done: #76905 (comment)
  • Loading branch information
JohnTitor authored Jul 4, 2021
2 parents 249d872 + ab86df0 commit 28dba82
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<'_> {
Expand Down

0 comments on commit 28dba82

Please sign in to comment.