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