boot_loader_name.rs 497 B

12345678910111213141516171819
  1. #[derive(Debug)]
  2. #[repr(packed)] // repr(C) would add unwanted padding before first_section
  3. pub struct BootLoaderNameTag {
  4. typ: u32,
  5. size: u32,
  6. string: u8,
  7. }
  8. impl BootLoaderNameTag {
  9. pub fn name(&self) -> &str {
  10. use core::{mem,str,slice};
  11. unsafe {
  12. let strlen = self.size as usize - mem::size_of::<BootLoaderNameTag>();
  13. str::from_utf8_unchecked(
  14. slice::from_raw_parts((&self.string) as *const u8, strlen))
  15. }
  16. }
  17. }