This is the example of how to use the methods of the ReadBytesExt trait of the byteorder crate:
use std::io::Cursor;
use byteorder::{BigEndian, ReadBytesExt};
let mut rdr = Cursor::new(vec![2, 5, 3, 0]);
assert_eq!(517, rdr.read_u16::<BigEndian>().unwrap());
assert_eq!(768, rdr.read_u16::<BigEndian>().unwrap());
This requires me to specify the byte order every time I call one of the methods on the reader:
rdr.read_u16::<BigEndian>()
Is there a way to get rid of that? Normally a type alias can be used to pack overly verbose type parameters into a convenient name, but I don't know how (and if) that is possible with the trait methods here.
Another option is to define your own local extension trait, implement it for the types you care about, and have the trait expose the helper function. Might be more convenient to do rdr.trait_read_u16() over freestanding_read_u16(&mut rdr).