File tree 2 files changed +26
-5
lines changed
2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -892,6 +892,21 @@ impl<'a> Formatter<'a> {
892
892
}
893
893
}
894
894
895
+ #[ stable( since = "1.2.0" , feature = "formatter_write" ) ]
896
+ impl < ' a > Write for Formatter < ' a > {
897
+ fn write_str ( & mut self , s : & str ) -> Result {
898
+ self . buf . write_str ( s)
899
+ }
900
+
901
+ fn write_char ( & mut self , c : char ) -> Result {
902
+ self . buf . write_char ( c)
903
+ }
904
+
905
+ fn write_fmt ( & mut self , args : Arguments ) -> Result {
906
+ write ( self . buf , args)
907
+ }
908
+ }
909
+
895
910
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
896
911
impl Display for Error {
897
912
fn fmt ( & self , f : & mut Formatter ) -> Result {
@@ -965,10 +980,7 @@ impl Debug for char {
965
980
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
966
981
impl Display for char {
967
982
fn fmt ( & self , f : & mut Formatter ) -> Result {
968
- let mut utf8 = [ 0 ; 4 ] ;
969
- let amt = self . encode_utf8 ( & mut utf8) . unwrap_or ( 0 ) ;
970
- let s: & str = unsafe { mem:: transmute ( & utf8[ ..amt] ) } ;
971
- Display :: fmt ( s, f)
983
+ f. write_char ( * self )
972
984
}
973
985
}
974
986
Original file line number Diff line number Diff line change 15
15
#![ allow( unknown_features) ]
16
16
#![ feature( box_syntax) ]
17
17
18
- use std:: fmt;
18
+ use std:: fmt:: { self , Write } ;
19
19
use std:: usize;
20
20
21
21
struct A ;
22
22
struct B ;
23
23
struct C ;
24
+ struct D ;
24
25
25
26
impl fmt:: LowerHex for A {
26
27
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
@@ -37,6 +38,13 @@ impl fmt::Display for C {
37
38
f. pad_integral ( true , "☃" , "123" )
38
39
}
39
40
}
41
+ impl fmt:: Binary for D {
42
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
43
+ try!( f. write_str ( "aa" ) ) ;
44
+ try!( f. write_char ( '☃' ) ) ;
45
+ f. write_str ( "bb" )
46
+ }
47
+ }
40
48
41
49
macro_rules! t {
42
50
( $a: expr, $b: expr) => { assert_eq!( $a, $b) }
@@ -90,6 +98,7 @@ pub fn main() {
90
98
t ! ( format!( "{foo_bar}" , foo_bar=1 ) , "1" ) ;
91
99
t ! ( format!( "{}" , 5 + 5 ) , "10" ) ;
92
100
t ! ( format!( "{:#4}" , C ) , "☃123" ) ;
101
+ t ! ( format!( "{:b}" , D ) , "aa☃bb" ) ;
93
102
94
103
let a: & fmt:: Debug = & 1 ;
95
104
t ! ( format!( "{:?}" , a) , "1" ) ;
You can’t perform that action at this time.
0 commit comments