I am trying to read in a file until the end 2 bytes at a time and I want to catch the EOF error:
use byteorder::{BigEndian, ReadBytesExt}; // 1.3.4
use std::fs::File;
fn main() {
let filename = "/etc/hosts";
let mut file = File::open(filename).expect("Cannot open file");
loop {
let binary = match file.read_u16::<BigEndian>() {
Ok(binary) => binary,
Err(e) => panic!("Can't read from file: {}, err {}", filename, e),
// Can I catch the EOF error here?
};
println!("{:?}", binary);
}
}