File tree Expand file tree Collapse file tree 5 files changed +62
-1
lines changed Expand file tree Collapse file tree 5 files changed +62
-1
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,10 @@ repository = "https://github.com/rust-osdev/multiboot2"
32
32
documentation = " https://docs.rs/multiboot2"
33
33
34
34
[features ]
35
- default = []
35
+ # by default, builder is included
36
+ default = [" builder" ]
37
+ std = []
38
+ builder = [" std" ]
36
39
# Nightly-only features that will eventually be stabilized.
37
40
unstable = []
38
41
Original file line number Diff line number Diff line change
1
+ //! Exports item [`Multiboot2InformationBuilder`].
2
+ use crate :: { builder:: traits:: StructAsBytes , CommandLineTag } ;
3
+
4
+ use alloc:: boxed:: Box ;
5
+
6
+ /// Builder to construct a valid Multiboot2 information dynamically at runtime.
7
+ /// The tags will appear in the order of their corresponding enumeration,
8
+ /// except for the END tag.
9
+ #[ derive( Debug ) ]
10
+ pub struct Multiboot2InformationBuilder { }
11
+
12
+ impl Multiboot2InformationBuilder {
13
+ pub const fn new ( ) -> Self {
14
+ Self { }
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ //! Module for the builder-feature.
2
+
3
+ mod information;
4
+ pub ( self ) mod traits;
5
+
6
+ pub use information:: Multiboot2InformationBuilder ;
Original file line number Diff line number Diff line change
1
+ //! Module for the helper trait [`StructAsBytes`].
2
+
3
+ use core:: mem:: size_of;
4
+
5
+ /// Trait for all tags that helps to create a byte array from the tag.
6
+ /// Useful in builders to construct a byte vector that
7
+ /// represents the Multiboot2 information with all its tags.
8
+ pub ( crate ) trait StructAsBytes : Sized {
9
+ /// Returns the size in bytes of the struct, as known during compile
10
+ /// time. This doesn't use read the "size" field of tags.
11
+ fn byte_size ( & self ) -> usize {
12
+ size_of :: < Self > ( )
13
+ }
14
+
15
+ /// Returns a byte pointer to the begin of the struct.
16
+ fn as_ptr ( & self ) -> * const u8 {
17
+ self as * const Self as * const u8
18
+ }
19
+
20
+ /// Returns the structure as a vector of its bytes.
21
+ /// The length is determined by [`Self::byte_size`].
22
+ fn struct_as_bytes ( & self ) -> alloc:: vec:: Vec < u8 > {
23
+ let ptr = self . as_ptr ( ) ;
24
+ let mut vec = alloc:: vec:: Vec :: with_capacity ( self . byte_size ( ) ) ;
25
+ for i in 0 ..self . byte_size ( ) {
26
+ vec. push ( unsafe { * ptr. add ( i) } )
27
+ }
28
+ vec
29
+ }
30
+ }
Original file line number Diff line number Diff line change 32
32
//! ## MSRV
33
33
//! The MSRV is 1.56.1 stable.
34
34
35
+ #[ cfg( feature = "builder" ) ]
36
+ extern crate alloc;
37
+
35
38
// this crate can use std in tests only
36
39
#[ cfg_attr( test, macro_use) ]
37
40
#[ cfg( test) ]
@@ -81,6 +84,9 @@ mod smbios;
81
84
mod tag_type;
82
85
mod vbe_info;
83
86
87
+ #[ cfg( feature = "builder" ) ]
88
+ pub mod builder;
89
+
84
90
/// Magic number that a multiboot2-compliant boot loader will store in `eax` register
85
91
/// right before handoff to the payload (the kernel). This value can be used to check,
86
92
/// that the kernel was indeed booted via multiboot2.
You can’t perform that action at this time.
0 commit comments