1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
use crate::Be32; use core::{mem, slice}; use plain::Plain; #[derive(Clone, Copy, Debug)] #[repr(packed)] pub struct File { pub magic: [u8; 8], pub len: Be32, pub kind: Be32, pub checksum: Be32, pub offset: Be32, } impl File { pub fn name(&self) -> &[u8] { unsafe { slice::from_raw_parts( (self as *const Self as *const u8).add(mem::size_of::<Self>()), u32::from(self.offset) as usize - mem::size_of::<Self>() ) } } pub fn data(&self) -> &[u8] { unsafe { slice::from_raw_parts( (self as *const Self as *const u8).add(u32::from(self.offset) as usize), u32::from(self.len) as usize ) } } } unsafe impl Plain for File {}