Builder

Struct Builder 

Source
pub struct Builder { /* private fields */ }
Expand description

Builder for a Multiboot2 header information.

Implementations§

Source§

impl Builder

Source

pub const fn new(arch: HeaderTagISA) -> Self

Set the RelocatableHeaderTag tag.

Examples found in repository?
examples/minimal.rs (line 13)
9fn main() {
10    // We create a Multiboot2 header during runtime here. A more practical
11    // example, however, would be that you parse the header from kernel binary
12    // at runtime.
13    let mb2_hdr_bytes = Builder::new(HeaderTagISA::I386)
14        .relocatable_tag(RelocatableHeaderTag::new(
15            HeaderTagFlag::Required,
16            0x1337,
17            0xdeadbeef,
18            4096,
19            RelocatableHeaderTagPreference::None,
20        ))
21        .information_request_tag(InformationRequestHeaderTag::new(
22            HeaderTagFlag::Required,
23            &[
24                MbiTagType::Cmdline.into(),
25                MbiTagType::BootLoaderName.into(),
26            ],
27        ))
28        .build();
29
30    // Cast bytes in vector to Multiboot2 information structure
31    let ptr = mb2_hdr_bytes.as_bytes().as_ptr();
32    let mb2_hdr = unsafe { Multiboot2Header::load(ptr.cast()) };
33    let mb2_hdr = mb2_hdr.unwrap();
34    println!("{mb2_hdr:#?}");
35}
Source

pub fn information_request_tag( self, information_request_tag: Box<InformationRequestHeaderTag>, ) -> Self

Examples found in repository?
examples/minimal.rs (lines 21-27)
9fn main() {
10    // We create a Multiboot2 header during runtime here. A more practical
11    // example, however, would be that you parse the header from kernel binary
12    // at runtime.
13    let mb2_hdr_bytes = Builder::new(HeaderTagISA::I386)
14        .relocatable_tag(RelocatableHeaderTag::new(
15            HeaderTagFlag::Required,
16            0x1337,
17            0xdeadbeef,
18            4096,
19            RelocatableHeaderTagPreference::None,
20        ))
21        .information_request_tag(InformationRequestHeaderTag::new(
22            HeaderTagFlag::Required,
23            &[
24                MbiTagType::Cmdline.into(),
25                MbiTagType::BootLoaderName.into(),
26            ],
27        ))
28        .build();
29
30    // Cast bytes in vector to Multiboot2 information structure
31    let ptr = mb2_hdr_bytes.as_bytes().as_ptr();
32    let mb2_hdr = unsafe { Multiboot2Header::load(ptr.cast()) };
33    let mb2_hdr = mb2_hdr.unwrap();
34    println!("{mb2_hdr:#?}");
35}
Source

pub const fn address_tag(self, address_tag: AddressHeaderTag) -> Self

Set the AddressHeaderTag tag.

Source

pub const fn entry_tag(self, entry_tag: EntryAddressHeaderTag) -> Self

Set the EntryAddressHeaderTag tag.

Source

pub const fn console_tag(self, console_tag: ConsoleHeaderTag) -> Self

Set the ConsoleHeaderTag tag.

Source

pub const fn framebuffer_tag( self, framebuffer_tag: FramebufferHeaderTag, ) -> Self

Set the FramebufferHeaderTag tag.

Source

pub const fn module_align_tag( self, module_align_tag: ModuleAlignHeaderTag, ) -> Self

Set the ModuleAlignHeaderTag tag.

Source

pub const fn efi_bs_tag(self, efi_bs_tag: EfiBootServiceHeaderTag) -> Self

Source

pub const fn efi_32_tag(self, efi_32_tag: EntryEfi32HeaderTag) -> Self

Set the EntryEfi32HeaderTag tag.

Source

pub const fn efi_64_tag(self, efi_64_tag: EntryEfi64HeaderTag) -> Self

Set the EntryEfi64HeaderTag tag.

Source

pub const fn relocatable_tag( self, relocatable_tag: RelocatableHeaderTag, ) -> Self

Set the RelocatableHeaderTag tag.

Examples found in repository?
examples/minimal.rs (lines 14-20)
9fn main() {
10    // We create a Multiboot2 header during runtime here. A more practical
11    // example, however, would be that you parse the header from kernel binary
12    // at runtime.
13    let mb2_hdr_bytes = Builder::new(HeaderTagISA::I386)
14        .relocatable_tag(RelocatableHeaderTag::new(
15            HeaderTagFlag::Required,
16            0x1337,
17            0xdeadbeef,
18            4096,
19            RelocatableHeaderTagPreference::None,
20        ))
21        .information_request_tag(InformationRequestHeaderTag::new(
22            HeaderTagFlag::Required,
23            &[
24                MbiTagType::Cmdline.into(),
25                MbiTagType::BootLoaderName.into(),
26            ],
27        ))
28        .build();
29
30    // Cast bytes in vector to Multiboot2 information structure
31    let ptr = mb2_hdr_bytes.as_bytes().as_ptr();
32    let mb2_hdr = unsafe { Multiboot2Header::load(ptr.cast()) };
33    let mb2_hdr = mb2_hdr.unwrap();
34    println!("{mb2_hdr:#?}");
35}
Source

pub fn build(self) -> Box<DynSizedStructure<Multiboot2BasicHeader>>

Returns properly aligned bytes on the heap representing a valid Multiboot2 header structure.

Examples found in repository?
examples/minimal.rs (line 28)
9fn main() {
10    // We create a Multiboot2 header during runtime here. A more practical
11    // example, however, would be that you parse the header from kernel binary
12    // at runtime.
13    let mb2_hdr_bytes = Builder::new(HeaderTagISA::I386)
14        .relocatable_tag(RelocatableHeaderTag::new(
15            HeaderTagFlag::Required,
16            0x1337,
17            0xdeadbeef,
18            4096,
19            RelocatableHeaderTagPreference::None,
20        ))
21        .information_request_tag(InformationRequestHeaderTag::new(
22            HeaderTagFlag::Required,
23            &[
24                MbiTagType::Cmdline.into(),
25                MbiTagType::BootLoaderName.into(),
26            ],
27        ))
28        .build();
29
30    // Cast bytes in vector to Multiboot2 information structure
31    let ptr = mb2_hdr_bytes.as_bytes().as_ptr();
32    let mb2_hdr = unsafe { Multiboot2Header::load(ptr.cast()) };
33    let mb2_hdr = mb2_hdr.unwrap();
34    println!("{mb2_hdr:#?}");
35}

Trait Implementations§

Source§

impl Debug for Builder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointee for T

Source§

type Metadata = ()

The metadata type for pointers and references to this type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.