From: Wedson Almeida Filho Date: Thu, 10 Nov 2022 16:41:34 +0000 (+0100) Subject: rust: str: add `fmt!` macro X-Git-Tag: v6.2-rc1~166^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ef32054942ee8d78cbcc2c97212e55b6f5f668f7;p=thirdparty%2Fkernel%2Flinux.git 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: Wedson Almeida Filho Reviewed-by: Gary Guo [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda --- diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index 17dc8d2733029..b771310fa4a49 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -583,3 +583,9 @@ impl Deref for CString { 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)*) ) +}