File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1084,4 +1084,10 @@ impl fmt::Write for String {
1084
1084
self . push_str ( s) ;
1085
1085
Ok ( ( ) )
1086
1086
}
1087
+
1088
+ #[ inline]
1089
+ fn write_char ( & mut self , c : char ) -> fmt:: Result {
1090
+ self . push ( c) ;
1091
+ Ok ( ( ) )
1092
+ }
1087
1093
}
Original file line number Diff line number Diff line change @@ -83,6 +83,23 @@ pub trait Write {
83
83
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
84
84
fn write_str ( & mut self , s : & str ) -> Result ;
85
85
86
+ /// Writes a `char` into this writer, returning whether the write succeeded.
87
+ ///
88
+ /// A single `char` may be encoded as more than one byte.
89
+ /// This method can only succeed if the entire byte sequence was successfully
90
+ /// written, and this method will not return until all data has been
91
+ /// written or an error occurs.
92
+ ///
93
+ /// # Errors
94
+ ///
95
+ /// This function will return an instance of `FormatError` on error.
96
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
97
+ fn write_char ( & mut self , c : char ) -> Result {
98
+ let mut utf_8 = [ 0u8 ; 4 ] ;
99
+ let bytes_written = c. encode_utf8 ( & mut utf_8) . unwrap_or ( 0 ) ;
100
+ self . write_str ( unsafe { mem:: transmute ( & utf_8[ ..bytes_written] ) } )
101
+ }
102
+
86
103
/// Glue for usage of the `write!` macro with implementers of this trait.
87
104
///
88
105
/// This method should generally not be invoked manually, but rather through
You can’t perform that action at this time.
0 commit comments