Skip to content

Commit

Permalink
XXX simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
phip1611 committed May 15, 2023
1 parent 64904c1 commit 4a6964e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 31 deletions.
9 changes: 0 additions & 9 deletions multiboot2/src/boot_loader_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ impl Debug for BootLoaderNameTag {
}
}

impl crate::TagTrait for BootLoaderNameTag {
fn dst_size(base_tag: &Tag) -> usize {
// The size of the sized portion of the bootloader name tag.
let tag_base_size = 8;
assert!(base_tag.size >= 8);
base_tag.size as usize - tag_base_size
}
}

#[cfg(test)]
mod tests {
use crate::{BootLoaderNameTag, Tag, TagType};
Expand Down
9 changes: 0 additions & 9 deletions multiboot2/src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ impl Debug for CommandLineTag {
}
}

impl TagTrait for CommandLineTag {
fn dst_size(base_tag: &Tag) -> usize {
// The size of the sized portion of the command line tag.
let tag_base_size = 8;
assert!(base_tag.size >= 8);
base_tag.size as usize - tag_base_size
}
}

#[cfg(test)]
mod tests {
use crate::{CommandLineTag, Tag, TagType};
Expand Down
21 changes: 17 additions & 4 deletions multiboot2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,14 @@ impl BootInformation {
/// }
///
/// // This implementation is only necessary for tags that are DSTs.
/// impl TagTrait for CustomTag {
/// /*impl TagTrait for CustomTag {
/// fn dst_size(base_tag: &Tag) -> usize {
/// // The size of the sized portion of the custom tag.
/// let tag_base_size = 8; // id + size is 8 byte in size
/// assert!(base_tag.size >= 8);
/// base_tag.size as usize - tag_base_size
/// }
/// }
/// }*/
///
/// impl CustomTag {
/// fn name(&self) -> Result<&str, Utf8Error> {
Expand Down Expand Up @@ -533,6 +533,19 @@ impl<T: Pointee<Metadata = ()>> TagTrait for T {
}
}

// All sized tags automatically have a Pointee implementation where
// Pointee::Metadata is (). Hence, the TagTrait is implemented automatically for
// all tags that are sized.
impl<T: Pointee<Metadata = usize>> TagTrait for T {
#[allow(clippy::unused_unit)]
fn dst_size(base_tag: &Tag) -> Self::Metadata {
// The size of the sized portion of the command line tag.
let tag_base_size = 8;
assert!(base_tag.size >= 8);
base_tag.size as usize - tag_base_size
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -1618,14 +1631,14 @@ mod tests {
}
}

impl TagTrait for CustomTag {
/*impl TagTrait for CustomTag {
fn dst_size(base_tag: &Tag) -> usize {
// The size of the sized portion of the command line tag.
let tag_base_size = 8;
assert!(base_tag.size >= 8);
base_tag.size as usize - tag_base_size
}
}
}*/

#[repr(C, align(8))]
struct AlignedBytes([u8; 32]);
Expand Down
9 changes: 0 additions & 9 deletions multiboot2/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ impl ModuleTag {
}
}

impl crate::TagTrait for ModuleTag {
fn dst_size(base_tag: &Tag) -> usize {
// The size of the sized portion of the module tag.
let tag_base_size = 16;
assert!(base_tag.size >= 8);
base_tag.size as usize - tag_base_size
}
}

impl Debug for ModuleTag {
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
f.debug_struct("ModuleTag")
Expand Down

0 comments on commit 4a6964e

Please sign in to comment.