Skip to content

Commit c3f41b0

Browse files
asahilinaojeda
authored andcommitted
rust: kernel: str: Implement Debug for CString
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]>
1 parent a39b6ac commit c3f41b0

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
@@ -608,6 +608,12 @@ impl<'a> TryFrom<&'a CStr> for CString {
608608
}
609609
}
610610

611+
impl fmt::Debug for CString {
612+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
613+
fmt::Debug::fmt(&**self, f)
614+
}
615+
}
616+
611617
/// A convenience alias for [`core::format_args`].
612618
#[macro_export]
613619
macro_rules! fmt {

0 commit comments

Comments
 (0)