Mercurial > touhou
diff examples/common.rs @ 752:5e5e7136ac92
examples: Return a Result for load_file_into_vec()
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Wed, 29 Jan 2020 17:45:25 +0100 |
parents | ee45bfde91bb |
children | a662dddd4a2b |
line wrap: on
line diff
--- a/examples/common.rs +++ b/examples/common.rs @@ -4,15 +4,15 @@ use luminance::texture::{Dim2, Flat, Sam use luminance_glfw::GlfwSurface; use touhou::th06::anm0::Anm0; use std::fs::File; -use std::io::{BufReader, Read}; +use std::io::{self, BufReader, Read}; use std::path::Path; -pub fn load_file_into_vec<P: AsRef<Path>>(filename: P) -> Vec<u8> { - let file = File::open(filename).unwrap(); +pub fn load_file_into_vec<P: AsRef<Path>>(filename: P) -> io::Result<Vec<u8>> { + let file = File::open(filename)?; let mut file = BufReader::new(file); let mut buf = vec![]; - file.read_to_end(&mut buf).unwrap(); - buf + file.read_to_end(&mut buf)?; + Ok(buf) } pub enum LoadedTexture {