@@ -55,8 +55,8 @@ pub use memory_map::{
55
55
} ;
56
56
pub use module:: { ModuleIter , ModuleTag } ;
57
57
pub use rsdp:: { RsdpV1Tag , RsdpV2Tag } ;
58
- pub use tag_type:: { Tag , TagType , TagTypeId } ;
59
58
use tag_type:: TagIter ;
59
+ pub use tag_type:: { Tag , TagType , TagTypeId } ;
60
60
pub use vbe_info:: {
61
61
VBECapabilities , VBEControlInfo , VBEDirectColorAttributes , VBEField , VBEInfoTag ,
62
62
VBEMemoryModel , VBEModeAttributes , VBEModeInfo , VBEWindowAttributes ,
@@ -308,7 +308,42 @@ impl BootInformation {
308
308
unsafe { & * self . inner }
309
309
}
310
310
311
- fn get_tag ( & self , typ : TagType ) -> Option < & Tag > {
311
+ /// Public getter to find any Multiboot tag by its type, including
312
+ /// specified and custom ones.
313
+ ///
314
+ /// # Specified or Custom Tags
315
+ /// The Multiboot2 specification specifies a list of tags, see [`TagType`].
316
+ /// However, it doesn't forbid to use custom tags. Because of this, there
317
+ /// exists the [`TagType`] abstraction. It is recommended to use this
318
+ /// getter only for custom tags. For specified tags, use getters, such as
319
+ /// [`Self::efi_64_ih`].
320
+ ///
321
+ /// ## Use Custom Tags
322
+ /// The following example shows how you may use this interface to parse custom tags from
323
+ /// the MBI.
324
+ ///
325
+ /// ```ignore
326
+ /// use multiboot2::TagTypeId;
327
+ /// #[repr(C, align(8))]
328
+ /// struct CustomTag {
329
+ /// // new type from the lib: has repr(u32)
330
+ /// tag: TagTypeId,
331
+ /// size: u32,
332
+ /// // begin of inline string
333
+ /// name: u8,
334
+ /// }
335
+ ///
336
+ /// let tag = bi
337
+ /// // this function is now public!
338
+ /// .get_tag(0x1337.into())
339
+ /// .unwrap()
340
+ /// // type definition from end user; must be `Sized`!
341
+ /// .cast_tag::<CustomTag>();
342
+ /// let name = &tag.name as *const u8 as *const c_char;
343
+ /// let str = unsafe { CStr::from_ptr(name).to_str().unwrap() };
344
+ /// assert_eq!(str, "name");
345
+ /// ```
346
+ pub fn get_tag ( & self , typ : TagType ) -> Option < & Tag > {
312
347
self . tags ( ) . find ( |tag| tag. typ == typ)
313
348
}
314
349
0 commit comments