diff --git a/src/header.rs b/src/header.rs index db836fe..d2bee22 100644 --- a/src/header.rs +++ b/src/header.rs @@ -1,7 +1,7 @@ use zerocopy::little_endian::U32; -use zerocopy::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; -#[derive(FromZeroes, FromBytes, AsBytes, Debug)] +#[derive(FromBytes, IntoBytes, Immutable, KnownLayout, Debug)] #[repr(C)] pub struct Header { pub(crate) id: U32, diff --git a/src/wrapper.rs b/src/wrapper.rs index 5b13443..c60c036 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -1,16 +1,15 @@ use crate::header::Header; use zerocopy::little_endian::U32; -use zerocopy::{AsBytes, ByteSlice, ByteSliceMut, Ref}; +use zerocopy::{SplitByteSlice, SplitByteSliceMut, Ref, IntoBytes}; -#[derive(Debug)] -pub struct Wrapper { - header: Ref, // Deprecated: Rename LayoutVerified to Ref #203 +pub struct Wrapper { + header: Ref, value: T, } -impl Wrapper { +impl Wrapper { pub fn deserialize(packed: T) -> Option { - let (header_lv, rest) = Ref::<_, Header>::new_from_prefix(packed)?; + let (header_lv, rest) = Ref::<_, Header>::from_prefix(packed).ok()?; let native_model = Self { header: header_lv, value: rest, @@ -35,7 +34,7 @@ impl Wrapper { } } -impl Wrapper { +impl Wrapper { pub fn set_type_id(&mut self, type_id: u32) { self.header.id = U32::new(type_id); }