specialize ToString for str
This commit is contained in:
parent
c7bdfd4442
commit
fc8cf9c5af
|
@ -48,6 +48,7 @@
|
||||||
#![feature(placement_new_protocol)]
|
#![feature(placement_new_protocol)]
|
||||||
#![feature(shared)]
|
#![feature(shared)]
|
||||||
#![feature(slice_patterns)]
|
#![feature(slice_patterns)]
|
||||||
|
#![feature(specialization)]
|
||||||
#![feature(staged_api)]
|
#![feature(staged_api)]
|
||||||
#![feature(step_by)]
|
#![feature(step_by)]
|
||||||
#![feature(str_char)]
|
#![feature(str_char)]
|
||||||
|
|
|
@ -1770,7 +1770,7 @@ pub trait ToString {
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl<T: fmt::Display + ?Sized> ToString for T {
|
impl<T: fmt::Display + ?Sized> ToString for T {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_string(&self) -> String {
|
default fn to_string(&self) -> String {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
let _ = buf.write_fmt(format_args!("{}", self));
|
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")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
impl AsRef<str> for String {
|
impl AsRef<str> for String {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
Loading…
Reference in New Issue