Skip to content

Commit

Permalink
rust: str: add fmt! macro
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
wedsonaf authored and ojeda committed Dec 4, 2022
1 parent 65e1e49 commit ef32054
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions rust/kernel/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)*) )
}

0 comments on commit ef32054

Please sign in to comment.