@@ -308,9 +308,21 @@ static USIZE_MARKER: fn(&usize, &mut Formatter<'_>) -> Result = |ptr, _| {
308308 loop { }
309309} ;
310310
311+ macro_rules! arg_new {
312+ ( $f: ident, $t: ident) => {
313+ #[ doc( hidden) ]
314+ #[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" , issue = "none" ) ]
315+ #[ inline]
316+ pub fn $f<' b, T : $t>( x: & ' b T ) -> ArgumentV1 <' _> {
317+ Self :: new( x, $t:: fmt)
318+ }
319+ } ;
320+ }
321+
311322impl < ' a > ArgumentV1 < ' a > {
312323 #[ doc( hidden) ]
313324 #[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" , issue = "none" ) ]
325+ #[ inline]
314326 pub fn new < ' b , T > ( x : & ' b T , f : fn ( & T , & mut Formatter < ' _ > ) -> Result ) -> ArgumentV1 < ' b > {
315327 // SAFETY: `mem::transmute(x)` is safe because
316328 // 1. `&'b T` keeps the lifetime it originated with `'b`
@@ -323,6 +335,16 @@ impl<'a> ArgumentV1<'a> {
323335 unsafe { ArgumentV1 { formatter : mem:: transmute ( f) , value : mem:: transmute ( x) } }
324336 }
325337
338+ arg_new ! ( new_display, Display ) ;
339+ arg_new ! ( new_debug, Debug ) ;
340+ arg_new ! ( new_octal, Octal ) ;
341+ arg_new ! ( new_lower_hex, LowerHex ) ;
342+ arg_new ! ( new_upper_hex, UpperHex ) ;
343+ arg_new ! ( new_pointer, Pointer ) ;
344+ arg_new ! ( new_binary, Binary ) ;
345+ arg_new ! ( new_lower_exp, LowerExp ) ;
346+ arg_new ! ( new_upper_exp, UpperExp ) ;
347+
326348 #[ doc( hidden) ]
327349 #[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" , issue = "none" ) ]
328350 pub fn from_usize ( x : & usize ) -> ArgumentV1 < ' _ > {
0 commit comments