1- use crate :: { formatter :: FormatterArgs , Display , Formatter , Result , StyleDiff } ;
1+ use crate :: { Display , Formatter , Result } ;
22
3- type StdFmtFn < ' a > = dyn Fn ( & mut core:: fmt:: Formatter < ' _ > ) -> Result + ' a ;
4-
5- #[ doc( hidden) ] // workaround https://github.com/rust-lang/rust/issues/85522
6- pub struct StdFmt < ' a > ( stack_dst:: ValueA < StdFmtFn < ' a > , [ usize ; 3 ] > ) ;
7-
8- impl < ' a > StdFmt < ' a > {
9- #[ doc( hidden) ] // workaround https://github.com/rust-lang/rust/issues/85526
10- pub fn new ( f : impl Fn ( & mut core:: fmt:: Formatter < ' _ > ) -> Result + ' a ) -> StdFmt < ' a > {
11- // not possible(/easy) to correctly type the closure, but with the cast
12- // inference works
13- #[ allow( trivial_casts) ]
14- StdFmt (
15- stack_dst:: ValueA :: new_stable ( f, |p| p as _ )
16- . map_err ( |_| ( ) )
17- . expect ( "StdFmt was more than 3 words, this is a bug in stylish-core" ) ,
18- )
19- }
3+ #[ doc( hidden) ]
4+ /// pub for macros
5+ pub struct StdFmt < ' a > {
6+ #[ doc( hidden) ]
7+ /// pub for macros
8+ pub f : & ' a ( dyn Fn ( & mut core:: fmt:: Formatter < ' _ > ) -> Result + ' a ) ,
209}
2110
2211impl core:: fmt:: Display for StdFmt < ' _ > {
12+ #[ inline]
2313 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> Result {
24- ( self . 0 ) ( f)
14+ ( self . f ) ( f)
2515 }
2616}
2717
2818impl core:: fmt:: Debug for StdFmt < ' _ > {
19+ #[ inline]
2920 fn fmt ( & self , f : & mut core:: fmt:: Formatter < ' _ > ) -> Result {
30- ( self . 0 ) ( f)
21+ ( self . f ) ( f)
3122 }
3223}
3324
34- #[ doc( hidden) ] // workaround https://github.com/rust-lang/rust/issues/85522
25+ #[ doc( hidden) ]
3526#[ allow( missing_debug_implementations) ]
36- pub enum FormatTrait < ' a > {
37- Display ( StdFmt < ' a > ) ,
38- Debug ( StdFmt < ' a > ) ,
39- Octal ( StdFmt < ' a > ) ,
40- LowerHex ( StdFmt < ' a > ) ,
41- UpperHex ( StdFmt < ' a > ) ,
42- Pointer ( StdFmt < ' a > ) ,
43- Binary ( StdFmt < ' a > ) ,
44- LowerExp ( StdFmt < ' a > ) ,
45- UpperExp ( StdFmt < ' a > ) ,
46- Stylish ( & ' a dyn Display ) ,
47- }
27+ /// pub for macros
28+ pub struct StdFmtOther < ' a > (
29+ #[ doc( hidden) ]
30+ /// pub for macros
31+ pub StdFmt < ' a > ,
32+ ) ;
4833
49- #[ doc( hidden) ] // workaround https://github.com/rust-lang/rust/issues/85522
34+ #[ doc( hidden) ]
5035#[ allow( missing_debug_implementations) ]
51- pub enum Argument < ' a > {
52- Lit ( & ' a str ) ,
53-
54- Arg {
55- args : & ' a FormatterArgs < ' a > ,
56- style : StyleDiff ,
57- arg : FormatTrait < ' a > ,
58- } ,
59- }
36+ /// pub for macros
37+ pub struct StdFmtDebug < ' a > (
38+ #[ doc( hidden) ]
39+ /// pub for macros
40+ pub StdFmt < ' a > ,
41+ ) ;
6042
6143/// A precompiled version of a format string and its by-reference arguments.
6244///
@@ -72,37 +54,30 @@ pub enum Argument<'a> {
7254/// ```
7355#[ allow( missing_debug_implementations) ]
7456pub struct Arguments < ' a > {
75- #[ doc( hidden) ] // pub for macros
76- pub pieces : & ' a [ Argument < ' a > ] ,
57+ #[ doc( hidden) ]
58+ /// pub for macros
59+ pub f : & ' a ( dyn Fn ( & mut Formatter < ' _ > ) -> Result + ' a ) ,
60+ }
61+
62+ impl Display for StdFmtOther < ' _ > {
63+ #[ inline]
64+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
65+ let arg = & self . 0 ;
66+ std_write ! ( f, Other , arg)
67+ }
7768}
7869
79- impl Display for FormatTrait < ' _ > {
70+ impl Display for StdFmtDebug < ' _ > {
71+ #[ inline]
8072 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
81- match self {
82- Self :: Display ( arg) => std_write ! ( f, Display , arg) ,
83- Self :: Debug ( arg) => std_write ! ( f, Debug , arg) ,
84- Self :: Octal ( arg) => std_write ! ( f, Display , arg) ,
85- Self :: LowerHex ( arg) => std_write ! ( f, Display , arg) ,
86- Self :: UpperHex ( arg) => std_write ! ( f, Display , arg) ,
87- Self :: Pointer ( arg) => std_write ! ( f, Display , arg) ,
88- Self :: Binary ( arg) => std_write ! ( f, Display , arg) ,
89- Self :: LowerExp ( arg) => std_write ! ( f, Display , arg) ,
90- Self :: UpperExp ( arg) => std_write ! ( f, Display , arg) ,
91- Self :: Stylish ( arg) => arg. fmt ( f) ,
92- }
73+ let arg = & self . 0 ;
74+ std_write ! ( f, Debug , arg)
9375 }
9476}
9577
9678impl Display for Arguments < ' _ > {
79+ #[ inline]
9780 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result {
98- for piece in self . pieces {
99- match piece {
100- Argument :: Lit ( lit) => f. write_str ( lit) ?,
101- Argument :: Arg { args, style, arg } => {
102- arg. fmt ( & mut f. with ( style) . with_args ( args) ) ?
103- }
104- }
105- }
106- Ok ( ( ) )
81+ ( self . f ) ( f)
10782 }
10883}
0 commit comments