-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} | ||
|
||
impl<T: Copy> ReadOnly<T> { | ||
/// Construct a new instance for testing. | ||
pub fn new(value: T) -> Self { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
} | ||
|
||
/// An MMIO register which may be both read and written. | ||
#[derive(Default)] | ||
#[repr(transparent)] | ||
|
@@ -27,6 +39,12 @@ impl<T: Copy> Volatile<T> { | |
} | ||
} | ||
|
||
impl<T: Debug + Copy> Debug for Volatile<T> { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result { | ||
f.debug_tuple("Volatile").field(&self.0).finish() | ||
} | ||
} | ||
|
||
/// A trait implemented by MMIO registers which may be read from. | ||
pub trait VolatileReadable<T> { | ||
/// Performs a volatile read from the MMIO register. | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Put these imports at the top of the file. |
||
|
||
pub(crate) use volread; | ||
pub(crate) use volwrite; |
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.