-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Debug trait implementation for ReadOnly, WriteOnly, and Volatile #126
Add Debug trait implementation for ReadOnly, WriteOnly, and Volatile #126
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would these Debug
implementations be used? These types are used to wrap MMIO registers, which can't just be read directly.
@@ -104,5 +122,7 @@ macro_rules! volwrite { | |||
}; | |||
} | |||
|
|||
use core::fmt::{Debug, Formatter}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put these imports at the top of the file.
@@ -3,6 +3,12 @@ | |||
#[repr(transparent)] | |||
pub struct ReadOnly<T: Copy>(T); | |||
|
|||
impl<T: Debug + Copy> Debug for ReadOnly<T> { | |||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the explicit lifetime <'_>
here and in the other implementation below.
@@ -15,6 +21,12 @@ impl<T: Copy> ReadOnly<T> { | |||
#[repr(transparent)] | |||
pub struct WriteOnly<T: Copy>(T); | |||
|
|||
impl<T: Debug + Copy> Debug for WriteOnly<T> { | |||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { | |||
f.debug_tuple("WriteOnly").field(&self.0).finish() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WriteOnly
is used to wrap MMIO registers which can only be written, so it doesn't make sense to read a value from it.
@@ -3,6 +3,12 @@ | |||
#[repr(transparent)] | |||
pub struct ReadOnly<T: Copy>(T); | |||
|
|||
impl<T: Debug + Copy> Debug for ReadOnly<T> { | |||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { | |||
f.debug_tuple("ReadOnly").field(&self.0).finish() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReadOnly
is intended to wrap MMIO registers which may have side-effects when reading, so it's probably not a good idea to implement Debug
, as adding debug output may change behaviour. Also any reading should be done with read_volatile
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, you are right, I didn't consider the issue of side effects.
No description provided.