//! Next type from bytes /// Parses some types from bytes pub trait NextFromBytes { /// Parses the next `u8` from bytes fn next_u8(&self) -> Option; /// Parses the next `u16` from bytes fn next_u16(&self) -> Option; /// Parses the next `u32` from bytes fn next_u32(&self) -> Option; } impl NextFromBytes for [u8] { fn next_u8(&self) -> Option { match *self { [a, ..] => Some(a), _ => None, } } fn next_u16(&self) -> Option { match *self { [a, b, ..] => Some(u16::from_ne_bytes([a, b])), _ => None, } } fn next_u32(&self) -> Option { match *self { [a, b, c, d, ..] => Some(u32::from_ne_bytes([a, b, c, d])), _ => None, } } }