Skip to content

Commit

Permalink
Auto merge of #39440 - F001:SpecializeCow, r=bluss
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Feb 4, 2017
2 parents 7df5c0f + dfcca54 commit 8568fdc
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libcollections/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 8568fdc

Please sign in to comment.