]> git.lizzy.rs Git - rust.git/commitdiff
Disable AsRef implementations for String's Drain.
authorMara Bos <m-ou.se@m-ou.se>
Wed, 9 Sep 2020 17:38:51 +0000 (19:38 +0200)
committerMara Bos <m-ou.se@m-ou.se>
Wed, 9 Sep 2020 17:57:57 +0000 (19:57 +0200)
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).

library/alloc/src/string.rs

index 047ae942cd9a25f5aa0f504aef9d4e9bf7209d4a..b9506281ed6291d4dc68a4db2ca618a9357b3646 100644 (file)
@@ -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<'_> {