diff options
| author | Sean McArthur <sean.monstar@gmail.com> | 2016-03-22 19:29:56 -0700 |
|---|---|---|
| committer | Sean McArthur <sean.monstar@gmail.com> | 2016-03-30 10:40:06 -0700 |
| commit | fc8cf9c5afd531e825b3ae9a57f618c149dd3893 (patch) | |
| tree | 0167dca0bdb9a1d59fe99f1b4dce4e528b8d248f | |
| parent | c7bdfd4442f0bde3412f08336f75b9eabff4a938 (diff) | |
| download | rust-fc8cf9c5afd531e825b3ae9a57f618c149dd3893.tar.gz rust-fc8cf9c5afd531e825b3ae9a57f618c149dd3893.zip | |
specialize ToString for str
| -rw-r--r-- | src/libcollections/lib.rs | 1 | ||||
| -rw-r--r-- | src/libcollections/string.rs | 10 |
2 files changed, 10 insertions, 1 deletions
diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index a6be81c91bb..8e62b389a6e 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -48,6 +48,7 @@ #![feature(placement_new_protocol)] #![feature(shared)] #![feature(slice_patterns)] +#![feature(specialization)] #![feature(staged_api)] #![feature(step_by)] #![feature(str_char)] diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 98225dd3dda..d552c99c21b 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1770,7 +1770,7 @@ pub trait ToString { #[stable(feature = "rust1", since = "1.0.0")] impl<T: fmt::Display + ?Sized> ToString for T { #[inline] - fn to_string(&self) -> String { + default fn to_string(&self) -> String { use core::fmt::Write; let mut buf = String::new(); let _ = buf.write_fmt(format_args!("{}", self)); @@ -1779,6 +1779,14 @@ impl<T: fmt::Display + ?Sized> ToString for T { } } +#[stable(feature = "str_to_string_specialization", since = "1.9.0")] +impl ToString for str { + #[inline] + fn to_string(&self) -> String { + String::from(self) + } +} + #[stable(feature = "rust1", since = "1.0.0")] impl AsRef<str> for String { #[inline] |
