summaryrefslogtreecommitdiffstats
path: root/rust/kernel/str.rs
diff options
context:
space:
mode:
authorWedson Almeida Filho <wedsonaf@gmail.com>2022-11-10 17:41:34 +0100
committerMiguel Ojeda <ojeda@kernel.org>2022-12-04 01:59:16 +0100
commitef32054942ee8d78cbcc2c97212e55b6f5f668f7 (patch)
tree8f559e3e167e3a738af52e38f8b9245e9a7e09c8 /rust/kernel/str.rs
parentrust: str: add `CString` type (diff)
downloadlinux-ef32054942ee8d78cbcc2c97212e55b6f5f668f7.tar.xz
linux-ef32054942ee8d78cbcc2c97212e55b6f5f668f7.zip
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 <wedsonaf@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
Diffstat (limited to 'rust/kernel/str.rs')
-rw-r--r--rust/kernel/str.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
index 17dc8d273302..b771310fa4a4 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)*) )
+}