]> git.lizzy.rs Git - rust.git/commitdiff
Add specialization of `ToString for char`
authorLzu Tao <taolzu@gmail.com>
Thu, 18 Jun 2020 02:54:35 +0000 (02:54 +0000)
committerLzu Tao <taolzu@gmail.com>
Thu, 18 Jun 2020 02:54:35 +0000 (02:54 +0000)
src/liballoc/string.rs

index 0378ff5362a8b9b0af6e2036e6d0ae1d128030f7..fa5757a0b11380515132401b732043111f868732 100644 (file)
@@ -2228,6 +2228,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]