Commit ef320549 authored by Wedson Almeida Filho's avatar Wedson Almeida Filho Committed by Miguel Ojeda

rust: str: add `fmt!` macro

Add the `fmt!` macro, which is a convenience alias for the Rust
`core::format_args!` macro.

For instance, it may be used to create a `CString`:

    CString::try_from_fmt(fmt!("{}{}", "abc", 42))?
Signed-off-by: default avatarWedson Almeida Filho <wedsonaf@gmail.com>
Reviewed-by: default avatarGary Guo <gary@garyguo.net>
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent 65e1e497
...@@ -583,3 +583,9 @@ fn deref(&self) -> &Self::Target { ...@@ -583,3 +583,9 @@ fn deref(&self) -> &Self::Target {
unsafe { CStr::from_bytes_with_nul_unchecked(self.buf.as_slice()) } unsafe { CStr::from_bytes_with_nul_unchecked(self.buf.as_slice()) }
} }
} }
/// A convenience alias for [`core::format_args`].
#[macro_export]
macro_rules! fmt {
($($f:tt)*) => ( core::format_args!($($f)*) )
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment