]> Git Repo - linux.git/commitdiff
rust: str: add `fmt!` macro
authorWedson Almeida Filho <[email protected]>
Thu, 10 Nov 2022 16:41:34 +0000 (17:41 +0100)
committerMiguel Ojeda <[email protected]>
Sun, 4 Dec 2022 00:59:16 +0000 (01:59 +0100)
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 <[email protected]>
Reviewed-by: Gary Guo <[email protected]>
[Reworded, adapted for upstream and applied latest changes]
Signed-off-by: Miguel Ojeda <[email protected]>
rust/kernel/str.rs

index 17dc8d2733029274290392f36137054c78e1db47..b771310fa4a49e0a1f2389f438784ec899725212 100644 (file)
@@ -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)*) )
+}
This page took 0.057319 seconds and 4 git commands to generate.