diff --git a/src/lib.rs b/src/lib.rs index 098cf16..01ba0f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -236,6 +236,48 @@ flt_impl_pop_non_ne!(f32); core_impl_pop_ne!(f64); flt_impl_pop_non_ne!(f64); +impl PopFromNE for [u8; SIZE] { + fn pop_ne_from(source: &mut &[u8]) -> Result + where + Self: Sized, + { + if source.len() < SIZE { + anyhow::bail!("Buffer to small to pop [u8; {SIZE}]"); + } + let value = source[..SIZE].try_into()?; + *source = &source[SIZE..]; + Ok(value) + } + + fn push_ne_into(&self, dest: &mut T) -> Result<()> { + dest.push_slice(self) + } +} +impl PopFromLE for [u8; SIZE] { + fn pop_le_from(source: &mut &[u8]) -> Result + where + Self: Sized, + { + Self::pop_ne_from(source) + } + + fn push_le_into(&self, dest: &mut T) -> Result<()> { + self.push_ne_into(dest) + } +} +impl PopFromBE for [u8; SIZE] { + fn pop_be_from(source: &mut &[u8]) -> Result + where + Self: Sized, + { + Self::pop_ne_from(source) + } + + fn push_be_into(&self, dest: &mut T) -> Result<()> { + self.push_ne_into(dest) + } +} + #[cfg(test)] mod tests { use super::*;