Some small refactors of constant functions
Getty Ritter
8 years ago
6 | 6 | bytes: Rd, |
7 | 7 | } |
8 | 8 | |
9 | const MK_OK: &'static Fn(io::Result<u8>) -> Option<u8> = &|s| s.ok(); | |
10 | ||
11 | 9 | impl<R: io::Read> |
12 | 10 | ByteReader<iter::FilterMap<io::Bytes<R>, |
13 | 11 | &'static Fn(io::Result<u8>) -> Option<u8>>> |
14 | 12 | { |
15 | 13 | /// Create a ByteReader from any type that implement Read |
16 | 14 | pub fn from_reader(r: R) -> Self { |
15 | const MK_OK: &'static Fn(io::Result<u8>) -> Option<u8> = &io::Result::<u8>::ok; | |
17 | 16 | let bytes = r.bytes().filter_map(MK_OK); |
18 | 17 | ByteReader { bytes: bytes } |
19 | 18 | } |
36 | 35 | } |
37 | 36 | } |
38 | 37 | |
39 | const DEREF: &'static Fn(&u8) -> u8 = &|s| *s; | |
40 | ||
41 | 38 | impl<'a> ByteReader<iter::Map<slice::Iter<'a, u8>, &'static Fn(&u8) -> u8>> { |
42 | 39 | /// Create a reader from a borrowed slice, with a copy on each access |
43 | 40 | pub fn from_slice(lst: &'a [u8]) -> Self { |
41 | const DEREF: &'static Fn(&u8) -> u8 = &|s| *s; | |
44 | 42 | ByteReader { bytes: lst.iter().map(DEREF) } |
45 | 43 | } |
46 | 44 | } |