@@ -308,9 +308,21 @@ static USIZE_MARKER: fn(&usize, &mut Formatter<'_>) -> Result = |ptr, _| {
308
308
loop { }
309
309
} ;
310
310
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
+
311
322
impl < ' a > ArgumentV1 < ' a > {
312
323
#[ doc( hidden) ]
313
324
#[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" , issue = "none" ) ]
325
+ #[ inline]
314
326
pub fn new < ' b , T > ( x : & ' b T , f : fn ( & T , & mut Formatter < ' _ > ) -> Result ) -> ArgumentV1 < ' b > {
315
327
// SAFETY: `mem::transmute(x)` is safe because
316
328
// 1. `&'b T` keeps the lifetime it originated with `'b`
@@ -323,6 +335,16 @@ impl<'a> ArgumentV1<'a> {
323
335
unsafe { ArgumentV1 { formatter : mem:: transmute ( f) , value : mem:: transmute ( x) } }
324
336
}
325
337
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
+
326
348
#[ doc( hidden) ]
327
349
#[ unstable( feature = "fmt_internals" , reason = "internal to format_args!" , issue = "none" ) ]
328
350
pub fn from_usize ( x : & usize ) -> ArgumentV1 < ' _ > {
0 commit comments