about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2020-06-19 09:15:18 -0700
committerGitHub <noreply@github.com>2020-06-19 09:15:18 -0700
commitd2272d4f6042ace97de2be1ebed4afa5e4be9f25 (patch)
treef8114c2a03f9fb9fef0fee44861ac224b072dad6 /src/liballoc
parentb443a107f8bb851bce4a9d7fb6fc0dd3fca17d9e (diff)
parente5c5df8f9c395e340d25ae70f828504148807af4 (diff)
downloadrust-d2272d4f6042ace97de2be1ebed4afa5e4be9f25.tar.gz
rust-d2272d4f6042ace97de2be1ebed4afa5e4be9f25.zip
Rollup merge of #73465 - lzutao:spec-char-tostring, r=sfackler
Add specialization of `ToString for char`

Closes #73462
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/string.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs
index 91b6d526796..64d9692244d 100644
--- a/src/liballoc/string.rs
+++ b/src/liballoc/string.rs
@@ -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]