-
Notifications
You must be signed in to change notification settings - Fork 18
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
Implement Debug for most types #30
Implement Debug for most types #30
Conversation
src/file.rs
Outdated
impl Debug for MediaType { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
&Self::GENERIC => write!(f, "MediaType::GENERIC"), | ||
&Self::OPTICAL => write!(f, "MediaType::OPTICAL"), | ||
&Self::TFTP => write!(f, "MediaType::TFTP"), | ||
_ => write!(f, "MediaType({})", self.0), | ||
} | ||
} | ||
} |
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.
Maybe use the derive(Debug)
style—exclude the type name, only include the value name.
src/file.rs
Outdated
|
||
match core::str::from_utf8(self.path()) { | ||
Ok(path) => x.field("path", &path), | ||
Err(err) => x.field("path", &err), |
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.
Just print bytes if the utf8 conversion fails fails.
src/file.rs
Outdated
x.field("tftp_ip", &self.tftp_ip()); | ||
x.field("tftp_port", &self.tftp_port()); | ||
#[cfg(feature = "ipaddr")] | ||
x.field("tftp_addr", &self.tftp_addr()); |
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.
Instead of having a separate tftp_addr
field, you could just print tftp_addr()
if the feature is enabled.
src/framebuffer.rs
Outdated
impl Debug for MemoryModel { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
&Self::RGB => write!(f, "MemoryModel::RGB"), | ||
_ => write!(f, "MemoryModel({})", self.0), | ||
} | ||
} | ||
} |
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.
See my comment on MediaType
.
src/framebuffer.rs
Outdated
x.field("edid", &format_args!("<{} bytes>", self.edid().len())); | ||
if let Some(modes) = self.modes() { | ||
x.field("modes", &format_args!("<{} modes>", modes.len())); | ||
} |
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.
Maybe print the full array if f.alternate()
is specified ({:#?}
).
src/memory_map.rs
Outdated
impl Debug for EntryType { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
match self { | ||
&Self::USABLE => write!(f, "EntryType::USABLE"), | ||
&Self::RESERVED => write!(f, "EntryType::RESERVED"), | ||
&Self::ACPI_RECLAIMABLE => write!(f, "EntryType::ACPI_RECLAIMABLE"), | ||
&Self::ACPI_NVS => write!(f, "EntryType::ACPI_NVS"), | ||
&Self::BAD_MEMORY => write!(f, "EntryType::BAD_MEMORY"), | ||
&Self::BOOTLOADER_RECLAIMABLE => write!(f, "EntryType::BOOTLOADER_RECLAIMABLE"), | ||
&Self::KERNEL_AND_MODULES => write!(f, "EntryType::KERNEL_AND_MODULES"), | ||
&Self::FRAMEBUFFER => write!(f, "EntryType::FRAMEBUFFER"), | ||
_ => write!(f, "EntryType({})", self.0), | ||
} | ||
} | ||
} |
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.
See comment on MediaType
.
src/paging.rs
Outdated
|
||
impl Debug for Mode { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] | ||
match self { | ||
&Self::FOUR_LEVEL => write!(f, "Mode::FOUR_LEVEL"), | ||
&Self::FIVE_LEVEL => write!(f, "Mode::FIVE_LEVEL"), | ||
_ => write!(f, "Mode({})", self.0), | ||
} | ||
|
||
#[cfg(target_arch = "riscv64")] | ||
match self { | ||
&Self::SV39 => write!(f, "Mode::SV39"), | ||
&Self::SV48 => write!(f, "Mode::SV48"), | ||
&Self::SV57 => write!(f, "Mode::SV57"), | ||
_ => write!(f, "Mode({})", self.0), | ||
} | ||
} | ||
} |
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.
See comment on MediaType
.
src/smp.rs
Outdated
impl Debug for GotoAddress { | ||
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { | ||
f.debug_tuple("GotoAddress") | ||
.field(&self.inner.as_ptr()) | ||
.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.
Have this be an opaque newtype.
Also, you'll have to rebase from #32. |
I've wrote an implementation of Debug for most types, but I can't figure out how to do
FrameBufferResponse
, since it gives an iterator and not a slice.Also should it print out all the framebuffer modes? There can be quite a lot of them (65 in my qemu configuration).