Skip to content

Commit

Permalink
Disable AsRef implementations for String's Drain.
Browse files Browse the repository at this point in the history
Since trait implementations cannot be unstable, we should only add them
when the as_str feature gets stabilized. Until then, only `.as_str()` is
available (behind a feature gate).
  • Loading branch information
m-ou-se committed Sep 9, 2020
1 parent f2a3290 commit 829019d
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2475,25 +2475,26 @@ impl<'a> Drain<'a> {
/// let _ = drain.next().unwrap();
/// assert_eq!(drain.as_str(), "bc");
/// ```
#[unstable(feature = "string_drain_as_str", issue = "none")]
#[unstable(feature = "string_drain_as_str", issue = "none")] // Note: uncomment AsRef impls below when stabilizing.
pub fn as_str(&self) -> &str {
self.iter.as_str()
}
}

#[stable(feature = "string_drain_as_ref", since = "1.48.0")]
impl<'a> AsRef<str> for Drain<'a> {
fn as_ref(&self) -> &str {
self.as_str()
}
}

#[stable(feature = "string_drain_as_ref", since = "1.48.0")]
impl<'a> AsRef<[u8]> for Drain<'a> {
fn as_ref(&self) -> &[u8] {
self.as_str().as_bytes()
}
}
// Uncomment when stabilizing `string_drain_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()
// }
// }
//
// #[unstable(feature = "string_drain_as_str", issue = "none")]
// 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 829019d

Please sign in to comment.