gdritter repos thermidor / 2e3aed7
Fixed the slice code, too Getty Ritter 8 years ago
1 changed file(s) with 9 addition(s) and 6 deletion(s). Collapse all Expand all
88
99 #[test]
1010 fn reader_tests() {
11 assert!(ByteReader::from_vec(vec![0x00]).read_twip() == Ok(-32.0));
12 assert!(ByteReader::from_vec(vec![0x00]).read_prefix_int() == Ok(0x00));
13 assert!(ByteReader::from_vec(vec![0x7f]).read_prefix_int() == Ok(0x7f));
14 assert!(ByteReader::from_vec(vec![0x80,0xff]).read_prefix_int() == Ok(0xff));
11 assert!(ByteReader::from_slice(&[0x00]).read_twip() == Ok(-32.0));
12 assert!(ByteReader::from_slice(&[0x00]).read_prefix_int() == Ok(0x00));
13 assert!(ByteReader::from_slice(&[0x7f]).read_prefix_int() == Ok(0x7f));
14 assert!(ByteReader::from_slice(&[0x80,0xff]).read_prefix_int() == Ok(0xff));
1515 }
1616
1717 const MK_OK: &'static Fn(io::Result<u8>) -> Option<u8> = &|s| s.ok();
4444 }
4545 }
4646
47 impl<'a> ByteReader<slice::Iter<'a, u8>> {
47 const DEREF: &'static Fn(&u8) -> u8 = &|s| *s;
48
49 impl<'a> ByteReader<iter::Map<slice::Iter<'a, u8>, &'static Fn(&u8) -> u8>> {
50 /// Create a reader from a borrowed slice, with a copy on each access
4851 pub fn from_slice(lst: &'a [u8]) -> Self {
49 ByteReader { bytes: lst.iter() }
52 ByteReader { bytes: lst.iter().map(DEREF) }
5053 }
5154 }
5255