1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
use std::io::{Read, Result}; pub trait ReadBytesExt: Read { #[inline(always)] fn read_u8(&mut self) -> Result<u8> { let mut buf = 0u8; self.read_exact(std::slice::from_mut(&mut buf))?; Ok(buf) } #[inline(always)] fn read_u16_be(&mut self) -> Result<u16> { let mut buf = [0u8; 2]; self.read_exact(&mut buf)?; Ok(u16::from_be_bytes(buf)) } } impl<T: Read> ReadBytesExt for T {}