[−][src]Macro const_format::coerce_to_fmt
Coerces a reference to a type that has a const_*_fmt
method.
Behavior
For arrays it coerces them into a slice, and wraps them in a PWrapper
.
For std types, it wraps them in a PWrapper
, which implements the
const_*_fmt
methods.
For std types, it just returns back the same reference.
Example
#![feature(const_mut_refs)] use const_format::{ for_examples::Unit, Formatter, FormattingFlags, PWrapper, StrWriter, coerce_to_fmt, strwriter_as_str, }; const CAP: usize = 128; const fn make_strwriter() -> StrWriter<[u8; CAP]> { let mut writer = StrWriter::new([0; CAP]); let mut fmt = Formatter::from_sw(&mut writer, FormattingFlags::NEW); // This is equivalent to the `PWrapper::slice(&[0u8, 1])` below let _ = coerce_to_fmt!([0u8, 1]).const_debug_fmt(&mut fmt); let _ = fmt.write_str(","); let _ = PWrapper::slice(&[0u8, 1]).const_debug_fmt(&mut fmt); let _ = fmt.write_str(","); // This is equivalent to the `PWrapper(100u32)` line let _ = coerce_to_fmt!(100u32).const_debug_fmt(&mut fmt); let _ = fmt.write_str(","); let _ = PWrapper(100u32).const_debug_fmt(&mut fmt); let _ = fmt.write_str(","); // This is equivalent to the `Unit.const_debug_fmt(&mut fmt)` line let _ = coerce_to_fmt!(Unit).const_debug_fmt(&mut fmt); let _ = fmt.write_str(","); let _ = Unit.const_debug_fmt(&mut fmt); writer } const TEXT: &str = strwriter_as_str!(&make_strwriter()); assert_eq!(TEXT, "[0, 1],[0, 1],100,100,Unit,Unit");