format_collect

This commit is contained in:
Johann Hemmann 2024-01-30 14:12:42 +01:00
parent d37f4e0d21
commit 771c6c9271
8 changed files with 54 additions and 39 deletions

View file

@ -24,6 +24,22 @@ macro_rules! format_to {
};
}
/// Appends formatted string to a `String` and returns the `String`.
///
/// Useful for folding iterators into a `String`.
#[macro_export]
macro_rules! format_to_acc {
($buf:expr, $lit:literal $($arg:tt)*) => {
{
use ::std::fmt::Write as _;
// We can't do ::std::fmt::Write::write_fmt($buf, format_args!($lit $($arg)*))
// unfortunately, as that loses out on autoref behavior.
_ = $buf.write_fmt(format_args!($lit $($arg)*));
$buf
}
};
}
/// Generates `From` impls for `Enum E { Foo(Foo), Bar(Bar) }` enums
///
/// # Example