Skip to content

Commit 1c68050

Browse files
committed
XXX simplify
1 parent f8e2849 commit 1c68050

File tree

4 files changed

+17
-31
lines changed

4 files changed

+17
-31
lines changed

multiboot2/src/boot_loader_name.rs

-9
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,6 @@ impl Debug for BootLoaderNameTag {
4343
}
4444
}
4545

46-
impl crate::TagTrait for BootLoaderNameTag {
47-
fn dst_size(base_tag: &Tag) -> usize {
48-
// The size of the sized portion of the bootloader name tag.
49-
let tag_base_size = 8;
50-
assert!(base_tag.size >= 8);
51-
base_tag.size as usize - tag_base_size
52-
}
53-
}
54-
5546
#[cfg(test)]
5647
mod tests {
5748
use crate::{BootLoaderNameTag, Tag, TagType};

multiboot2/src/command_line.rs

-9
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ impl Debug for CommandLineTag {
5050
}
5151
}
5252

53-
impl TagTrait for CommandLineTag {
54-
fn dst_size(base_tag: &Tag) -> usize {
55-
// The size of the sized portion of the command line tag.
56-
let tag_base_size = 8;
57-
assert!(base_tag.size >= 8);
58-
base_tag.size as usize - tag_base_size
59-
}
60-
}
61-
6253
#[cfg(test)]
6354
mod tests {
6455
use crate::{CommandLineTag, Tag, TagType};

multiboot2/src/lib.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -340,14 +340,14 @@ impl BootInformation {
340340
/// }
341341
///
342342
/// // This implementation is only necessary for tags that are DSTs.
343-
/// impl TagTrait for CustomTag {
343+
/// /*impl TagTrait for CustomTag {
344344
/// fn dst_size(base_tag: &Tag) -> usize {
345345
/// // The size of the sized portion of the custom tag.
346346
/// let tag_base_size = 8; // id + size is 8 byte in size
347347
/// assert!(base_tag.size >= 8);
348348
/// base_tag.size as usize - tag_base_size
349349
/// }
350-
/// }
350+
/// }*/
351351
///
352352
/// impl CustomTag {
353353
/// fn name(&self) -> Result<&str, Utf8Error> {
@@ -533,6 +533,19 @@ impl<T: Pointee<Metadata = ()>> TagTrait for T {
533533
}
534534
}
535535

536+
// All sized tags automatically have a Pointee implementation where
537+
// Pointee::Metadata is (). Hence, the TagTrait is implemented automatically for
538+
// all tags that are sized.
539+
impl<T: Pointee<Metadata = usize>> TagTrait for T {
540+
#[allow(clippy::unused_unit)]
541+
fn dst_size(base_tag: &Tag) -> Self::Metadata {
542+
// The size of the sized portion of the command line tag.
543+
let tag_base_size = 8;
544+
assert!(base_tag.size >= 8);
545+
base_tag.size as usize - tag_base_size
546+
}
547+
}
548+
536549
#[cfg(test)]
537550
mod tests {
538551
use super::*;
@@ -1618,14 +1631,14 @@ mod tests {
16181631
}
16191632
}
16201633

1621-
impl TagTrait for CustomTag {
1634+
/*impl TagTrait for CustomTag {
16221635
fn dst_size(base_tag: &Tag) -> usize {
16231636
// The size of the sized portion of the command line tag.
16241637
let tag_base_size = 8;
16251638
assert!(base_tag.size >= 8);
16261639
base_tag.size as usize - tag_base_size
16271640
}
1628-
}
1641+
}*/
16291642

16301643
#[repr(C, align(8))]
16311644
struct AlignedBytes([u8; 32]);

multiboot2/src/module.rs

-9
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ impl ModuleTag {
4444
}
4545
}
4646

47-
impl crate::TagTrait for ModuleTag {
48-
fn dst_size(base_tag: &Tag) -> usize {
49-
// The size of the sized portion of the module tag.
50-
let tag_base_size = 16;
51-
assert!(base_tag.size >= 8);
52-
base_tag.size as usize - tag_base_size
53-
}
54-
}
55-
5647
impl Debug for ModuleTag {
5748
fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
5849
f.debug_struct("ModuleTag")

0 commit comments

Comments
 (0)