Skip to content

Commit

Permalink
rust: kernel: str: Implement Debug for CString
Browse files Browse the repository at this point in the history
Make it possible to use a `CString` with the `pr_*` macros directly. That
is, instead of:

    pr_debug!("trying to open {:?}\n", &*filename);

we can now write:

    pr_debug!("trying to open {:?}\n", filename);

Signed-off-by: Asahi Lina <[email protected]>
Reviewed-by: Alice Ryhl <[email protected]>
Reviewed-by: Benno Lossin <[email protected]>
Reviewed-by: Martin Rodriguez Reboredo <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
[ Reworded to use Alice's commit message as discussed. ]
Signed-off-by: Miguel Ojeda <[email protected]>
  • Loading branch information
asahilina authored and ojeda committed Dec 12, 2023
1 parent a39b6ac commit c3f41b0
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 @@ -608,6 +608,12 @@ impl<'a> TryFrom<&'a CStr> for CString {
}
}

impl fmt::Debug for CString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(&**self, f)
}
}

/// A convenience alias for [`core::format_args`].
#[macro_export]
macro_rules! fmt {
Expand Down

0 comments on commit c3f41b0

Please sign in to comment.