Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit ef32054

Browse files
wedsonafojeda
authored andcommitted
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 <[email protected]> Reviewed-by: Gary Guo <[email protected]> [Reworded, adapted for upstream and applied latest changes] Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 65e1e49 commit ef32054

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

rust/kernel/str.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,3 +583,9 @@ impl Deref for CString {
583583
unsafe { CStr::from_bytes_with_nul_unchecked(self.buf.as_slice()) }
584584
}
585585
}
586+
587+
/// A convenience alias for [`core::format_args`].
588+
#[macro_export]
589+
macro_rules! fmt {
590+
($($f:tt)*) => ( core::format_args!($($f)*) )
591+
}

0 commit comments

Comments
 (0)