macro_rules! aformat {
($c:literal, $($arg:tt)*) => { ... };
($s:ty, $($arg:tt)*) => { ... };
}arraystring only.Expand description
Formats an ArrayString.
This macro, similar to the standard std::format!, formats a string yielding
Result<ArrayString>. This allows formatting a string on stack, without memory allocation.
Note that, unlike the standard macro, this macro is fallible. ArrayString is a fixed-capacity
data structure, whose capacity may be not enough for formatting an arbitrary string.
See lformat! for a macro that returns a plain ArrayString, while possibly truncating the
result.
This macro is a convenience wrapper of the format function.
ยงExamples
Format an ArrayString specifying the capacity only. The resulting type uses Usize as
length type and Uninitialized as spare memory policy.
let s = aformat!(16, "Hello, world!")?;
assert_eq!(s, "Hello, world!");
assert_eq!(s.capacity(), 16);Format an ArrayString specifying the array-string type.
This allows customization of length type and spare memory policy.
type A = ArrayString<16, U8, Pattern<0xCD>>;
let s = aformat!(A, "Hello, world!")?;
assert_eq!(s, "Hello, world!");Note that the macro may fail when there is no enough capacity.
assert!(aformat!(2, "Hello, world!").is_err());