format_buf/
lib.rs

1/// A drop-in replacement for `std::format!`, which can optionally accept a an
2/// existing `String` buffer.
3///
4/// ```rust
5/// use format_buf::format;
6///
7/// let mut buf = format!("Roses are {},\n", "red");
8/// let () = format!(buf, "Violets are {}.", "blue");
9/// assert_eq!(buf, "\
10///     Roses are red,\n\
11///     Violets are blue.\
12/// ")
13/// ```
14#[macro_export]
15macro_rules! format {
16    () => (::std::format!());
17    ($lit:literal $($arg:tt)*) => (::std::format!($lit $($arg)*));
18    ($buf:expr, $lit:literal $($arg:tt)*) => {
19        { use ::std::fmt::Write as _; let _ = ::std::write!($buf, $lit $($arg)*); }
20    };
21}