about summary refs log tree commit diff
path: root/src/libcollections
diff options
context:
space:
mode:
authorf001 <changchun.fan@qq.com>2017-02-01 11:54:36 +0800
committerf001 <changchun.fan@qq.com>2017-02-01 19:17:51 +0800
commitdfcca546fcbdab16b2696550820b0cea5ea7a894 (patch)
treec6e05351b8325ef0e9a7eee71dd44355cf9a6bb0 /src/libcollections
parent24055d0f2aa8dce5caed7544e6006aa48dceaea5 (diff)
downloadrust-dfcca546fcbdab16b2696550820b0cea5ea7a894.tar.gz
rust-dfcca546fcbdab16b2696550820b0cea5ea7a894.zip
std: Add ToString trait specialization for Cow<'a, str> and String
r? @bluss
Diffstat (limited to 'src/libcollections')
-rw-r--r--src/libcollections/string.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs
index b184a8603e6..9a985061ebb 100644
--- a/src/libcollections/string.rs
+++ b/src/libcollections/string.rs
@@ -1866,6 +1866,22 @@ impl ToString for str {
     }
 }
 
+#[stable(feature = "cow_str_to_string_specialization", since = "1.17.0")]
+impl<'a> ToString for Cow<'a, str> {
+    #[inline]
+    fn to_string(&self) -> String {
+        self[..].to_owned()
+    }
+}
+
+#[stable(feature = "string_to_string_specialization", since = "1.17.0")]
+impl ToString for String {
+    #[inline]
+    fn to_string(&self) -> String {
+        self.to_owned()
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl AsRef<str> for String {
     #[inline]