aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsahi Lina <[email protected]>2023-07-14 18:19:33 +0900
committerMiguel Ojeda <[email protected]>2023-12-13 00:13:49 +0100
commitc3f41b00307f796756ec494b90c9e238800a0ff8 (patch)
treea4e816f4958a1be4590e12ac94b1d6cfb7ef10ae
parenta39b6ac3781d46ba18193c9dbb2110f31e9bffe9 (diff)
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]>
-rw-r--r--rust/kernel/str.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/rust/kernel/str.rs b/rust/kernel/str.rs
index c41607b2e4fe..7d848b83add4 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 {