|
@@ -6,14 +6,13 @@ pub struct ByteReader<Rd> {
|
|
|
bytes: Rd,
|
|
|
}
|
|
|
|
|
|
-const MK_OK: &'static Fn(io::Result<u8>) -> Option<u8> = &|s| s.ok();
|
|
|
-
|
|
|
impl<R: io::Read>
|
|
|
ByteReader<iter::FilterMap<io::Bytes<R>,
|
|
|
&'static Fn(io::Result<u8>) -> Option<u8>>>
|
|
|
{
|
|
|
/// Create a ByteReader from any type that implement Read
|
|
|
pub fn from_reader(r: R) -> Self {
|
|
|
+ const MK_OK: &'static Fn(io::Result<u8>) -> Option<u8> = &io::Result::<u8>::ok;
|
|
|
let bytes = r.bytes().filter_map(MK_OK);
|
|
|
ByteReader { bytes: bytes }
|
|
|
}
|
|
@@ -36,11 +35,10 @@ impl ByteReader<vec::IntoIter<u8>> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const DEREF: &'static Fn(&u8) -> u8 = &|s| *s;
|
|
|
-
|
|
|
impl<'a> ByteReader<iter::Map<slice::Iter<'a, u8>, &'static Fn(&u8) -> u8>> {
|
|
|
/// Create a reader from a borrowed slice, with a copy on each access
|
|
|
pub fn from_slice(lst: &'a [u8]) -> Self {
|
|
|
+ const DEREF: &'static Fn(&u8) -> u8 = &|s| *s;
|
|
|
ByteReader { bytes: lst.iter().map(DEREF) }
|
|
|
}
|
|
|
}
|