]> git.lizzy.rs Git - rust.git/commitdiff
convert: add Into<Cow> impls for &str and String
authorSean McArthur <sean.monstar@gmail.com>
Mon, 30 Mar 2015 19:07:16 +0000 (12:07 -0700)
committerSean McArthur <sean.monstar@gmail.com>
Mon, 30 Mar 2015 19:07:16 +0000 (12:07 -0700)
src/libcollections/string.rs

index 7131c1cd881b4ccf95ed043e792566279d95d388..1b69898e167e302177a3dfcb68a4f5b6140ca55d 100644 (file)
@@ -1019,11 +1019,28 @@ fn as_ref(&self) -> &str {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a> From<&'a str> for String {
+    #[inline]
     fn from(s: &'a str) -> String {
         s.to_string()
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<'a> From<&'a str> for Cow<'a, str> {
+    #[inline]
+    fn from(s: &'a str) -> Cow<'a, str> {
+        Cow::Borrowed(s)
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<'a> From<String> for Cow<'a, str> {
+    #[inline]
+    fn from(s: String) -> Cow<'a, str> {
+        Cow::Owned(s)
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl Into<Vec<u8>> for String {
     fn into(self) -> Vec<u8> {
@@ -1031,7 +1048,7 @@ fn into(self) -> Vec<u8> {
     }
 }
 
-#[stable(feature = "rust1", since = "1.0.0")]
+#[unstable(feature = "into_cow", reason = "may be replaced by `convert::Into`")]
 impl IntoCow<'static, str> for String {
     #[inline]
     fn into_cow(self) -> Cow<'static, str> {
@@ -1039,7 +1056,7 @@ fn into_cow(self) -> Cow<'static, str> {
     }
 }
 
-#[stable(feature = "rust1", since = "1.0.0")]
+#[unstable(feature = "into_cow", reason = "may be replaced by `convert::Into`")]
 impl<'a> IntoCow<'a, str> for &'a str {
     #[inline]
     fn into_cow(self) -> Cow<'a, str> {