Created
August 22, 2016 08:46
-
-
Save aleics/a8d450709763534229058158b9f03701 to your computer and use it in GitHub Desktop.
How to properly and efficiently read a file in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn file_to_bytes(path: &Path) -> Result<Vec<u8>, std::io::Error> { | |
File::open(path).and_then(|mut file| { | |
let mut bytes = Vec::new(); | |
try!(file.read_to_end(&mut bytes)); | |
Ok(bytes) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment