Skip to content

streamline default derives #144

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

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion multiboot2-header/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::mem::size_of;
/// format, but it must be provided if the image is in a.out format or in some
/// other format. Required for legacy boot (BIOS).
/// Determines load addresses.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct AddressHeaderTag {
typ: HeaderTagType,
Expand Down
2 changes: 1 addition & 1 deletion multiboot2-header/src/builder/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use core::mem::size_of;
/// Builder to construct a valid Multiboot2 header dynamically at runtime.
/// The tags will appear in the order of their corresponding enumeration,
/// except for the END tag.
#[derive(Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Multiboot2HeaderBuilder {
arch: HeaderTagISA,
// first
Expand Down
2 changes: 1 addition & 1 deletion multiboot2-header/src/builder/information_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use multiboot2::TagTypeId;
/// at runtime. The information request tag has a dedicated builder because this way one
/// can dynamically attach several requests to it. Otherwise, the number of requested tags
/// must be known at compile time.
#[derive(Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg(feature = "builder")]
pub struct InformationRequestHeaderTagBuilder {
flag: HeaderTagFlag,
Expand Down
4 changes: 2 additions & 2 deletions multiboot2-header/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::mem::size_of;

/// Possible flags for [`ConsoleHeaderTag`].
#[repr(u32)]
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum ConsoleHeaderTagFlags {
/// Console required.
ConsoleRequired = 0,
Expand All @@ -13,7 +13,7 @@ pub enum ConsoleHeaderTagFlags {

/// Tells that a console must be available in MBI.
/// Only relevant for legacy BIOS.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct ConsoleHeaderTag {
typ: HeaderTagType,
Expand Down
2 changes: 1 addition & 1 deletion multiboot2-header/src/end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{HeaderTagFlag, HeaderTagType};
use core::mem::size_of;

/// Terminates a list of optional tags in a Multiboot2 header.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct EndHeaderTag {
// u16 value
Expand Down
2 changes: 1 addition & 1 deletion multiboot2-header/src/entry_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::mem::size_of;

/// Specifies the physical address to which the boot loader should jump in
/// order to start running the operating system. Not needed for ELF files.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct EntryAddressHeaderTag {
typ: HeaderTagType,
Expand Down
2 changes: 1 addition & 1 deletion multiboot2-header/src/entry_efi_32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::mem::size_of;
///
/// Technically, this is equivalent to the [`crate::EntryAddressHeaderTag`] but with a different
/// [`crate::HeaderTagType`].
#[derive(Copy, Clone)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct EntryEfi32HeaderTag {
typ: HeaderTagType,
Expand Down
2 changes: 1 addition & 1 deletion multiboot2-header/src/entry_efi_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use core::mem::size_of;
///
/// Technically, this is equivalent to the [`crate::EntryAddressHeaderTag`] but with a different
/// [`crate::HeaderTagType`].
#[derive(Copy, Clone)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct EntryEfi64HeaderTag {
typ: HeaderTagType,
Expand Down
2 changes: 1 addition & 1 deletion multiboot2-header/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::mem::size_of;
/// is present the bootloader assumes that the payload
/// has framebuffer support. Note: This is only a
/// recommended mode. Only relevant on legacy BIOS.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct FramebufferHeaderTag {
typ: HeaderTagType,
Expand Down
4 changes: 2 additions & 2 deletions multiboot2-header/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<'a> Debug for Multiboot2Header<'a> {

/// Errors that can occur when parsing a header from a slice.
/// See [`Multiboot2Header::find_header`].
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum LoadError {
/// The checksum does not match the data.
ChecksumMismatch,
Expand All @@ -226,7 +226,7 @@ impl core::error::Error for LoadError {}
///
/// The "basic" Multiboot2 header. This means only the properties, that are known during
/// compile time. All other information are derived during runtime from the size property.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct Multiboot2BasicHeader {
/// Must be the value of [`MULTIBOOT2_HEADER_MAGIC`].
Expand Down
4 changes: 2 additions & 2 deletions multiboot2-header/src/information_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use multiboot2::TagType;

/// Specifies what specific tag types the bootloader should provide
/// inside the mbi.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct InformationRequestHeaderTag<const N: usize> {
typ: HeaderTagType,
Expand Down Expand Up @@ -126,7 +126,7 @@ impl<'a> Iterator for InformationRequestHeaderTagIter<'a> {
impl<'a> Debug for InformationRequestHeaderTagIter<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let mut debug = f.debug_list();
(*self).for_each(|e| {
self.for_each(|e| {
debug.entry(&e);
});
debug.finish()
Expand Down
2 changes: 1 addition & 1 deletion multiboot2-header/src/module_align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{HeaderTagFlag, HeaderTagType};
use core::mem::size_of;

/// If this tag is present, provided boot modules must be page aligned.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct ModuleAlignHeaderTag {
typ: HeaderTagType,
Expand Down
4 changes: 2 additions & 2 deletions multiboot2-header/src/relocatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::mem::size_of;
/// but not lower than min addr and ‘2’ means load image at highest possible
/// address but not higher than max addr.
#[repr(u32)]
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum RelocatableHeaderTagPreference {
/// Let boot loader decide.
None = 0,
Expand All @@ -19,7 +19,7 @@ pub enum RelocatableHeaderTagPreference {
}

/// This tag indicates that the image is relocatable.
#[derive(Copy, Clone)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(C)]
pub struct RelocatableHeaderTag {
typ: HeaderTagType,
Expand Down
8 changes: 4 additions & 4 deletions multiboot2-header/src/tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/// ISA/ARCH in Multiboot2 header.
#[repr(u32)]
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum HeaderTagISA {
/// Spec: "means 32-bit (protected) mode of i386".
/// Caution: This is confusing. If you use the EFI64-tag
Expand All @@ -19,7 +19,7 @@ pub enum HeaderTagISA {
/// from the example C code at the bottom of the Multiboot2 specification. This value
/// stands in the `typ` property of [`crate::tags::HeaderTag`].
#[repr(u16)]
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum HeaderTagType {
/// Type for [`crate::EndHeaderTag`].
End = 0,
Expand Down Expand Up @@ -54,7 +54,7 @@ impl HeaderTagType {

/// Flags for Multiboot2 header tags.
#[repr(u16)]
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum HeaderTagFlag {
Required = 0,
Optional = 1,
Expand All @@ -63,7 +63,7 @@ pub enum HeaderTagFlag {
/// Common properties for all header tags. Other tags may have additional fields
/// that depend on the `typ` and the `size` field. All tags share the same beginning of the
/// struct.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct HeaderTag {
// u16 value
Expand Down
2 changes: 1 addition & 1 deletion multiboot2-header/src/uefi_bs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::mem::size_of;

/// This tag indicates that payload supports starting without terminating UEFI boot services.
/// Or in other words: The payload wants to use UEFI boot services.
#[derive(Copy, Clone, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct EfiBootServiceHeaderTag {
typ: HeaderTagType,
Expand Down
4 changes: 2 additions & 2 deletions multiboot2/src/boot_loader_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use {
const METADATA_SIZE: usize = size_of::<TagTypeId>() + size_of::<u32>();

/// The bootloader name tag.
#[derive(ptr_meta::Pointee)]
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
#[derive(ptr_meta::Pointee, PartialEq, Eq)]
#[repr(C)]
pub struct BootLoaderNameTag {
typ: TagTypeId,
size: u32,
Expand Down
1 change: 1 addition & 0 deletions multiboot2/src/builder/information.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use core::mem::size_of;
/// The tags will appear in the order of their corresponding enumeration,
/// except for the END tag.
#[derive(Debug)]
// #[derive(Debug, PartialEq, Eq)] // wait for uefi-raw 0.3.0
pub struct Multiboot2InformationBuilder {
basic_memory_info_tag: Option<BasicMemoryInfoTag>,
boot_loader_name_tag: Option<Box<BootLoaderNameTag>>,
Expand Down
4 changes: 2 additions & 2 deletions multiboot2/src/command_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ pub(crate) const METADATA_SIZE: usize = mem::size_of::<TagTypeId>() + mem::size_
///
/// The string is a normal C-style UTF-8 zero-terminated string that can be
/// obtained via the `command_line` method.
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
#[derive(ptr_meta::Pointee)]
#[derive(ptr_meta::Pointee, PartialEq, Eq)]
#[repr(C)]
pub struct CommandLineTag {
typ: TagTypeId,
size: u32,
Expand Down
10 changes: 5 additions & 5 deletions multiboot2/src/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use core::mem::size_of;
use crate::builder::traits::StructAsBytes;

/// EFI system table in 32 bit mode
#[derive(Clone, Copy, Debug)]
#[repr(C, packed)] // only repr(C) would add unwanted padding before first_section
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct EFISdt32 {
typ: TagTypeId,
size: u32,
Expand Down Expand Up @@ -41,7 +41,7 @@ impl StructAsBytes for EFISdt32 {
}

/// EFI system table in 64 bit mode
#[derive(Clone, Copy, Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct EFISdt64 {
typ: TagTypeId,
Expand Down Expand Up @@ -73,7 +73,7 @@ impl StructAsBytes for EFISdt64 {
}

/// Contains pointer to boot loader image handle.
#[derive(Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct EFIImageHandle32 {
typ: TagTypeId,
Expand Down Expand Up @@ -105,7 +105,7 @@ impl StructAsBytes for EFIImageHandle32 {
}

/// Contains pointer to boot loader image handle.
#[derive(Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct EFIImageHandle64 {
typ: TagTypeId,
Expand Down
8 changes: 4 additions & 4 deletions multiboot2/src/elf_sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>() + 4 * size_of::<u32>();
/// This tag contains section header table from an ELF kernel.
///
/// The sections iterator is provided via the `sections` method.
#[derive(ptr_meta::Pointee)]
#[repr(C, packed)]
#[derive(ptr_meta::Pointee, PartialEq, Eq)]
#[repr(C)]
pub struct ElfSectionsTag {
typ: TagTypeId,
pub(crate) size: u32,
Expand Down Expand Up @@ -142,7 +142,7 @@ impl Default for ElfSectionIter {
}

/// A single generic ELF Section.
#[derive(Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct ElfSection {
inner: *const u8,
string_section: *const u8,
Expand Down Expand Up @@ -353,7 +353,7 @@ impl ElfSectionInner for ElfSectionInner64 {
}

/// An enum abstraction over raw ELF section types.
#[derive(PartialEq, Eq, Debug, Copy, Clone)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u32)]
pub enum ElfSectionType {
/// This value marks the section header as inactive; it does not have an
Expand Down
23 changes: 17 additions & 6 deletions multiboot2/src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const METADATA_SIZE: usize = size_of::<TagTypeId>()
+ 2 * size_of::<u8>();

/// The VBE Framebuffer information Tag.
#[derive(Eq, ptr_meta::Pointee)]
#[repr(C, packed)]
#[derive(ptr_meta::Pointee, Eq)]
#[repr(C)]
pub struct FramebufferTag {
typ: TagTypeId,
size: u32,
Expand Down Expand Up @@ -244,7 +244,7 @@ impl TryFrom<u8> for FramebufferTypeId {
}

/// The type of framebuffer.
#[derive(Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum FramebufferType<'a> {
/// Indexed color.
Indexed {
Expand Down Expand Up @@ -300,7 +300,7 @@ impl<'a> FramebufferType<'a> {
}

/// An RGB color type field.
#[derive(Debug, PartialEq, Eq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct FramebufferField {
/// Color field position.
pub position: u8,
Expand All @@ -317,8 +317,8 @@ impl StructAsBytes for FramebufferField {
}

/// A framebuffer color descriptor in the palette.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(C, packed)] // only repr(C) would add unwanted padding at the end
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(C)] // no align(8) here is correct
pub struct FramebufferColor {
/// The Red component of the color.
pub red: u8,
Expand All @@ -344,3 +344,14 @@ impl StructAsBytes for FramebufferColor {
size_of::<Self>()
}
}

#[cfg(test)]
mod tests {
use super::*;

// Compile time test
#[test]
fn test_size() {
assert_eq!(size_of::<FramebufferColor>(), 3)
}
}
2 changes: 1 addition & 1 deletion multiboot2/src/image_load_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use {

/// If the image has relocatable header tag, this tag contains the image's
/// base physical address.
#[derive(Debug)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(C)]
pub struct ImageLoadPhysAddr {
typ: TagTypeId,
Expand Down
4 changes: 2 additions & 2 deletions multiboot2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub unsafe fn load_with_offset(

/// Error type that describes errors while loading/parsing a multiboot2 information structure
/// from a given address.
#[derive(Debug, Display)]
#[derive(Display, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum MbiLoadError {
/// The address is invalid. Make sure that the address is 8-byte aligned,
/// according to the spec.
Expand Down Expand Up @@ -385,7 +385,7 @@ impl BootInformation {
/// use std::str::Utf8Error;
/// use multiboot2::{Tag, TagTrait, TagTypeId};
///
/// #[repr(C, align(8))]
/// #[repr(C)]
/// #[derive(multiboot2::Pointee)] // Only needed for DSTs.
/// struct CustomTag {
/// // new type from the lib: has repr(u32)
Expand Down
Loading