Rollup merge of #73465 - lzutao:spec-char-tostring, r=sfackler

Add specialization of `ToString for char`

Closes #73462
This commit is contained in:
Manish Goregaokar 2020-06-19 09:15:18 -07:00 committed by GitHub
commit d2272d4f60
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2230,6 +2230,14 @@ impl<T: fmt::Display + ?Sized> ToString for T {
}
}
#[stable(feature = "char_to_string_specialization", since = "1.46.0")]
impl ToString for char {
#[inline]
fn to_string(&self) -> String {
String::from(self.encode_utf8(&mut [0; 4]))
}
}
#[stable(feature = "str_to_string_specialization", since = "1.9.0")]
impl ToString for str {
#[inline]