Skip to main content

multiboot2_header/
end.rs

1use crate::{HeaderTagFlag, HeaderTagHeader, HeaderTagType};
2use multiboot2_common::{MaybeDynSized, Tag};
3
4/// Terminates a list of optional tags in a Multiboot2 header.
5#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
6#[repr(C, align(8))]
7pub struct EndHeaderTag {
8    header: HeaderTagHeader,
9}
10
11const _: () = assert!(size_of::<EndHeaderTag>() == 2 + 2 + 4);
12
13impl Default for EndHeaderTag {
14    fn default() -> Self {
15        Self::new()
16    }
17}
18
19impl EndHeaderTag {
20    /// Constructs a new tag.
21    #[must_use]
22    pub const fn new() -> Self {
23        let header = HeaderTagHeader::new(
24            HeaderTagType::End,
25            HeaderTagFlag::Required,
26            size_of::<Self>() as u32,
27        );
28        Self { header }
29    }
30
31    /// Returns the [`HeaderTagType`].
32    #[must_use]
33    pub const fn typ(&self) -> HeaderTagType {
34        self.header.typ()
35    }
36
37    /// Returns the [`HeaderTagFlag`]s.
38    #[must_use]
39    pub const fn flags(&self) -> HeaderTagFlag {
40        self.header.flags()
41    }
42
43    /// Returns the size.
44    #[must_use]
45    pub const fn size(&self) -> u32 {
46        self.header.size()
47    }
48}
49
50// SAFETY: The tag is repr(C) with the header as first field, any bit
51// pattern is valid, and `BASE_SIZE`/`dst_len` match the ABI.
52unsafe impl MaybeDynSized for EndHeaderTag {
53    type Header = HeaderTagHeader;
54
55    const BASE_SIZE: usize = size_of::<Self>();
56}
57
58impl Tag for EndHeaderTag {
59    type IDType = HeaderTagType;
60    const ID: HeaderTagType = HeaderTagType::End;
61}