Skip to content

Commit

Permalink
Auto merge of #32586 - seanmonstar:speialize-to-string, r=alexcrichton
Browse files Browse the repository at this point in the history
specialize ToString for str

If there was some conditional compiling we could do, such that this impl only exists in nightly, and is turned off in beta/stable, I think that'd be an improvement here, as we could test specialization out without affecting stable builds.
  • Loading branch information
bors committed Apr 1, 2016
2 parents a2f0cc6 + fc8cf9c commit 3b342fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#![feature(placement_new_protocol)]
#![feature(shared)]
#![feature(slice_patterns)]
#![feature(specialization)]
#![feature(staged_api)]
#![feature(step_by)]
#![feature(str_char)]
Expand Down
10 changes: 9 additions & 1 deletion src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,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));
Expand All @@ -1764,6 +1764,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]
Expand Down

0 comments on commit 3b342fa

Please sign in to comment.