rust: kernel: str: Implement Debug for CString
PATCH 1/1 rust: kernel: str: Implement Debug for CString
Trivial implementation.
--- rust/kernel/str.rs | 6 ++++++ 1 file changed, 6 insertions(+)
rust/kernel/str.rs +6 -0
@@ -606,6 +606,12 @@ fn try_from(cstr: &'a CStr) -> Result<CString, AllocError> { } } +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 {
---
base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230714-cstring-debug-ca021fe0ad78
Thank you,
~~ Lina
Quoted 3 lines · Asahi Lina
Trivial implementation.
Signed-off-by Asahi Lina <[email protected]>
The commit message is a bit short, but the change itself looks fine.
Quoted 8 lines · Alice Ryhl
Quoted 3 lines · Asahi Lina
Trivial implementation.
Signed-off-by Asahi Lina <[email protected]>The commit message is a bit short, but the change itself looks fine.
Reviewed-by Alice Ryhl <[email protected]>
It's so trivial I just didn't know what else to write... suggestions welcome (for this or next time I have a patch like this) ^^
~~ Lina
Martin Rodriguez Reboredo
Reviewed-byQuoted 6 lines · Asahi Lina
Quoted 5 lines · Alice Ryhl
Quoted 3 lines · Asahi Lina
Trivial implementation.
Signed-off-by Asahi Lina <[email protected]>
Quoted 9 lines
Quoted 3 lines
The commit message is a bit short, but the change itself looks fine.
Reviewed-by Alice Ryhl <[email protected]>It's so trivial I just didn't know what else to write... suggestions welcome (for this or next time I have a patch like this) ^^
~~ Lina
Just describe what it does, like "cast the CStr to an &str and call fmt::Debug::fmt with it". I'll add my Reviewed-by, so retain it in case it's asked to change the commit message.
Quoted 30 lines · Asahi Lina
Trivial implementation.
Signed-off-by Asahi Lina <[email protected]>--- rust/kernel/str.rs | 6 ++++++ 1 file changed, 6 insertions(+)rust/kernel/str.rs +6
-1@@ -606,6 +606,12 @@ fn try_from(cstr: &'a CStr) -> Result<CString, AllocError> { } } +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 { ---base-commit:
06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230714-cstring-debug-ca021fe0ad78
Quoted 3 lines
Thank you,
~~ Lina
Glad I wasn't the only one missing this, now I don't have to write the awkard &* anymore, as in:
```
pr_debug!("trying to open {:?}\n", &*filename);
```Cheers,
Ariel
Alice Ryhl
reviewerQuoted 6 lines · Asahi Lina
Quoted 5 lines · Alice Ryhl
Quoted 3 lines · Asahi Lina
Trivial implementation.
Signed-off-by Asahi Lina <[email protected]>
Quoted 8 lines
Quoted 3 lines
The commit message is a bit short, but the change itself looks fine.
Reviewed-by Alice Ryhl <[email protected]>It's so trivial I just didn't know what else to write... suggestions welcome (for this or next time I have a patch like this) ^^
~ Lina
Adding some sort of motivation usually works quite well, e.g.:
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);Alice
Quoted 11 lines · Alice Ryhl
Adding some sort of motivation usually works quite well, e.g.:
Make it possible to use a CString with the
pr_*macros directly, that is, instead ofpr_debug!("trying to open {:?}\n", &*filename);we can now write
pr_debug!("trying to open {:?}\n", filename);
Indeed, this would be the most important bit, i.e. answering the "why?".
The "what?" and the "how?" are pretty much explained by the title, but it is also fine giving more details (but if the implementation requires an explanation, then it is usually best to write an actual source code comment instead).
Cheers,
Miguel
Quoted 15 lines · Miguel Ojeda
Quoted 11 lines · Alice Ryhl
Adding some sort of motivation usually works quite well, e.g.:
Make it possible to use a CString with the
pr_*macros directly, that is, instead ofpr_debug!("trying to open {:?}\n", &*filename);we can now write
pr_debug!("trying to open {:?}\n", filename);Indeed, this would be the most important bit, i.e. answering the "why?".
Quoted 7 lines
The "what?" and the "how?" are pretty much explained by the title, but it is also fine giving more details (but if the implementation requires an explanation, then it is usually best to write an actual source code comment instead).
Cheers,
Miguel
Any follow-up on this? It sure would make my logging cleaner.
Cheers,
Ariel
Quoted 2 lines · Ariel Miculas (amiculas)
Any follow-up on this? It sure would make my logging cleaner.
We were expecting a new version, but I can pick it up with e.g. the message that Alice suggested (i.e. marking it as modified by me).
Cheers,
Miguel
Quoted 3 lines · Asahi Lina
Trivial implementation.
Signed-off-by Asahi Lina <[email protected]>
With a better commit message you can add
Signature · 2 lines
Cheers, Benno
Quoted 29 lines
--- rust/kernel/str.rs | 6 ++++++ 1 file changed, 6 insertions(+)rust/kernel/str.rs +6
-1@@ -606,6 +606,12 @@ fn try_from(cstr: &'a CStr) -> Result<CString, AllocError> { } } +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 { ---base-commit:
06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
change-id: 20230714-cstring-debug-ca021fe0ad78Thank you,
~~ Lina
Miguel Ojeda
AppliedQuoted 4 lines · Asahi Lina
Trivial implementation.
Signed-off-by Asahi Lina <[email protected]>
Applied to rust-next with the commit message from Alice.
Thanks everyone!
Cheers,
Miguel