about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2017-02-04 10:04:06 +0000
committerbors <bors@rust-lang.org>2017-02-04 10:04:06 +0000
commit8568fdc499453397351230f71c9df85e95a340bc (patch)
tree61da79b645d5765a4fb7f06a0646ae0f700e8436
parent7df5c0f17b2966bd7e6cd4326f990fe844254a4f (diff)
parentdfcca546fcbdab16b2696550820b0cea5ea7a894 (diff)
downloadrust-8568fdc499453397351230f71c9df85e95a340bc.tar.gz
rust-8568fdc499453397351230f71c9df85e95a340bc.zip
Auto merge of #39440 - F001:SpecializeCow, r=bluss
std: Add ToString trait specialization for Cow<'a, str> and String

There is a specialized version of ToString for str type in std. I think there are other types can also benefit from specialization. `Cow` and `String` are the most obvious one.

r? @bluss
-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]