From: Lzu Tao Date: Thu, 18 Jun 2020 02:54:35 +0000 (+0000) Subject: Add specialization of `ToString for char` X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;ds=sidebyside;h=e5c5df8f9c395e340d25ae70f828504148807af4;p=rust.git Add specialization of `ToString for char` --- diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 0378ff5362a..fa5757a0b11 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -2228,6 +2228,14 @@ impl 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]