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