From: Asahi Lina Date: Fri, 14 Jul 2023 09:19:33 +0000 (+0900) Subject: rust: kernel: str: Implement Debug for CString X-Git-Tag: v6.8-rc1~126^2~12 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c3f41b00307f796756ec494b90c9e238800a0ff8;p=thirdparty%2Fkernel%2Flinux.git 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 Reviewed-by: Alice Ryhl Reviewed-by: Benno Lossin Reviewed-by: Martin Rodriguez Reboredo Link: https://lore.kernel.org/r/20230714-cstring-debug-v1-1-4e7c3018dd4f@asahilina.net [ Reworded to use Alice's commit message as discussed. ] Signed-off-by: Miguel Ojeda --- diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs index c41607b2e4fe9..7d848b83add48 100644 --- a/rust/kernel/str.rs +++ b/rust/kernel/str.rs @@ -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 {