@@ -264,7 +264,7 @@ impl BootInformation {
264
264
/// Search for the Memory map tag.
265
265
pub fn memory_map_tag ( & self ) -> Option < & MemoryMapTag > {
266
266
self . get_tag ( TagType :: Mmap )
267
- . map ( |tag| tag. cast_tag :: < MemoryMapTag > ( ) )
267
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const MemoryMapTag ) } )
268
268
}
269
269
270
270
/// Search for the Memory map tag, return a mutable reference.
@@ -281,20 +281,20 @@ impl BootInformation {
281
281
/// Search for the BootLoader name tag.
282
282
pub fn boot_loader_name_tag ( & self ) -> Option < & BootLoaderNameTag > {
283
283
self . get_tag ( TagType :: BootLoaderName )
284
- . map ( |tag| tag. cast_tag :: < BootLoaderNameTag > ( ) )
284
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const BootLoaderNameTag ) } )
285
285
}
286
286
287
287
/// Search for the Command line tag.
288
288
pub fn command_line_tag ( & self ) -> Option < & CommandLineTag > {
289
289
self . get_tag ( TagType :: Cmdline )
290
- . map ( |tag| tag. cast_tag :: < CommandLineTag > ( ) )
290
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const CommandLineTag ) } )
291
291
}
292
292
293
293
/// Search for the VBE framebuffer tag. The result is `Some(Err(e))`, if the
294
294
/// framebuffer type is unknown, while the framebuffer tag is present.
295
295
pub fn framebuffer_tag ( & self ) -> Option < Result < & FramebufferTag , UnknownFramebufferType > > {
296
296
self . get_tag ( TagType :: Framebuffer )
297
- . map ( |tag| tag. cast_tag :: < FramebufferTag > ( ) )
297
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const FramebufferTag ) } )
298
298
. map ( |tag| match tag. buffer_type ( ) {
299
299
Ok ( _) => Ok ( tag) ,
300
300
Err ( e) => Err ( e) ,
@@ -304,25 +304,25 @@ impl BootInformation {
304
304
/// Search for the EFI 32-bit SDT tag.
305
305
pub fn efi_sdt_32_tag ( & self ) -> Option < & EFISdt32 > {
306
306
self . get_tag ( TagType :: Efi32 )
307
- . map ( |tag| tag. cast_tag :: < EFISdt32 > ( ) )
307
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const EFISdt32 ) } )
308
308
}
309
309
310
310
/// Search for the EFI 64-bit SDT tag.
311
311
pub fn efi_sdt_64_tag ( & self ) -> Option < & EFISdt64 > {
312
312
self . get_tag ( TagType :: Efi64 )
313
- . map ( |tag| tag. cast_tag :: < EFISdt64 > ( ) )
313
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const EFISdt64 ) } )
314
314
}
315
315
316
316
/// Search for the (ACPI 1.0) RSDP tag.
317
317
pub fn rsdp_v1_tag ( & self ) -> Option < & RsdpV1Tag > {
318
318
self . get_tag ( TagType :: AcpiV1 )
319
- . map ( |tag| tag. cast_tag :: < RsdpV1Tag > ( ) )
319
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const RsdpV1Tag ) } )
320
320
}
321
321
322
322
/// Search for the (ACPI 2.0 or later) RSDP tag.
323
323
pub fn rsdp_v2_tag ( & self ) -> Option < & RsdpV2Tag > {
324
324
self . get_tag ( TagType :: AcpiV2 )
325
- . map ( |tag| tag. cast_tag :: < RsdpV2Tag > ( ) )
325
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const RsdpV2Tag ) } )
326
326
}
327
327
328
328
/// Search for the EFI Memory map tag, if the boot services were exited.
@@ -336,7 +336,7 @@ impl BootInformation {
336
336
Some ( _tag) => None ,
337
337
None => self
338
338
. get_tag ( TagType :: EfiMmap )
339
- . map ( |tag| tag. cast_tag :: < EFIMemoryMapTag > ( ) ) ,
339
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const EFIMemoryMapTag ) } ) ,
340
340
}
341
341
}
342
342
@@ -349,25 +349,25 @@ impl BootInformation {
349
349
/// Search for the EFI 32-bit image handle pointer.
350
350
pub fn efi_32_ih ( & self ) -> Option < & EFIImageHandle32 > {
351
351
self . get_tag ( TagType :: Efi32Ih )
352
- . map ( |tag| tag. cast_tag :: < EFIImageHandle32 > ( ) )
352
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const EFIImageHandle32 ) } )
353
353
}
354
354
355
355
/// Search for the EFI 64-bit image handle pointer.
356
356
pub fn efi_64_ih ( & self ) -> Option < & EFIImageHandle64 > {
357
357
self . get_tag ( TagType :: Efi64Ih )
358
- . map ( |tag| tag. cast_tag :: < EFIImageHandle64 > ( ) )
358
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const EFIImageHandle64 ) } )
359
359
}
360
360
361
361
/// Search for the Image Load Base Physical Address.
362
362
pub fn load_base_addr ( & self ) -> Option < & ImageLoadPhysAddr > {
363
363
self . get_tag ( TagType :: LoadBaseAddr )
364
- . map ( |tag| tag. cast_tag :: < ImageLoadPhysAddr > ( ) )
364
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const ImageLoadPhysAddr ) } )
365
365
}
366
366
367
367
/// Search for the VBE information tag.
368
368
pub fn vbe_info_tag ( & self ) -> Option < & VBEInfoTag > {
369
369
self . get_tag ( TagType :: Vbe )
370
- . map ( |tag| tag. cast_tag :: < VBEInfoTag > ( ) )
370
+ . map ( |tag| unsafe { & * ( tag as * const Tag as * const VBEInfoTag ) } )
371
371
}
372
372
373
373
fn get ( & self ) -> & BootInformationInner {
@@ -395,7 +395,7 @@ impl BootInformation {
395
395
/// **Belows example needs Rust 1.64 or newer because of std::ffi imports!**
396
396
/// ```rust,no_run
397
397
/// use std::ffi::{c_char, CStr};
398
- /// use multiboot2::TagTypeId;
398
+ /// use multiboot2::{Tag, TagTypeId} ;
399
399
///
400
400
/// #[repr(C, align(8))]
401
401
/// struct CustomTag {
@@ -410,9 +410,9 @@ impl BootInformation {
410
410
///
411
411
/// let tag = mbi
412
412
/// .get_tag(0x1337)
413
- /// .unwrap()
414
- /// // type definition from end user; must be `Sized`!
415
- /// .cast_tag::<CustomTag>() ;
413
+ /// .unwrap();
414
+ /// // type definition from end user; must be `Sized`!
415
+ /// let tag = unsafe { &*(tag as *const Tag as *const CustomTag) } ;
416
416
/// let name = &tag.name as *const u8 as *const c_char;
417
417
/// let str = unsafe { CStr::from_ptr(name).to_str().unwrap() };
418
418
/// assert_eq!(str, "name");
@@ -422,14 +422,9 @@ impl BootInformation {
422
422
self . tags ( ) . find ( |tag| tag. typ == typ)
423
423
}
424
424
425
- fn get_tag_mut < Tag : ?Sized , TagType : Into < TagTypeId > > (
426
- & mut self ,
427
- typ : TagType ,
428
- ) -> Option < & mut Tag > {
425
+ fn get_tag_mut ( & mut self , typ : impl Into < TagTypeId > ) -> Option < & mut Tag > {
429
426
let typ = typ. into ( ) ;
430
- self . tags_mut ( )
431
- . find ( |tag| tag. typ == typ)
432
- . map ( |tag| tag. cast_tag_mut :: < Tag > ( ) )
427
+ self . tags_mut ( ) . find ( |tag| tag. typ == typ)
433
428
}
434
429
435
430
fn tags ( & self ) -> TagIter {
@@ -1587,7 +1582,8 @@ mod tests {
1587
1582
name : u8 ,
1588
1583
}
1589
1584
1590
- let tag = bi. get_tag ( CUSTOM_TAG_ID ) . unwrap ( ) . cast_tag :: < CustomTag > ( ) ;
1585
+ let tag = bi. get_tag ( CUSTOM_TAG_ID ) . unwrap ( ) ;
1586
+ let tag = unsafe { & * ( tag as * const Tag as * const CustomTag ) } ;
1591
1587
1592
1588
// strlen without null byte
1593
1589
let strlen = tag. size as usize - command_line:: METADATA_SIZE ;
0 commit comments