gdritter repos thermidor / c8c1f4a
Some small refactors of constant functions Getty Ritter 7 years ago
1 changed file(s) with 2 addition(s) and 4 deletion(s). Collapse all Expand all
66 bytes: Rd,
77 }
88
9 const MK_OK: &'static Fn(io::Result<u8>) -> Option<u8> = &|s| s.ok();
10
119 impl<R: io::Read>
1210 ByteReader<iter::FilterMap<io::Bytes<R>,
1311 &'static Fn(io::Result<u8>) -> Option<u8>>>
1412 {
1513 /// Create a ByteReader from any type that implement Read
1614 pub fn from_reader(r: R) -> Self {
15 const MK_OK: &'static Fn(io::Result<u8>) -> Option<u8> = &io::Result::<u8>::ok;
1716 let bytes = r.bytes().filter_map(MK_OK);
1817 ByteReader { bytes: bytes }
1918 }
3635 }
3736 }
3837
39 const DEREF: &'static Fn(&u8) -> u8 = &|s| *s;
40
4138 impl<'a> ByteReader<iter::Map<slice::Iter<'a, u8>, &'static Fn(&u8) -> u8>> {
4239 /// Create a reader from a borrowed slice, with a copy on each access
4340 pub fn from_slice(lst: &'a [u8]) -> Self {
41 const DEREF: &'static Fn(&u8) -> u8 = &|s| *s;
4442 ByteReader { bytes: lst.iter().map(DEREF) }
4543 }
4644 }