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