Mercurial > touhou
diff examples/stdrenderer.rs @ 700:ccb739c5b66c
examples: factorise file reading into a buffer.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 23 Aug 2019 13:05:48 +0200 |
parents | ef2dbd676a91 |
children | b6c351ca0a35 |
line wrap: on
line diff
--- a/examples/stdrenderer.rs +++ b/examples/stdrenderer.rs @@ -107,6 +107,14 @@ struct ShaderInterface { fog_color: Uniform<[f32; 4]>, } +fn load_file_into_vec(filename: &str) -> Vec<u8> { + let file = File::open(filename).unwrap(); + let mut file = BufReader::new(file); + let mut buf = vec![]; + file.read_to_end(&mut buf).unwrap(); + buf +} + fn main() { // Parse arguments. let args: Vec<_> = env::args().collect(); @@ -119,17 +127,11 @@ fn main() { let png_filename = &args[3]; // Open the STD file. - let file = File::open(std_filename).unwrap(); - let mut file = BufReader::new(file); - let mut buf = vec![]; - file.read_to_end(&mut buf).unwrap(); + let buf = load_file_into_vec(std_filename); let (_, stage) = Stage::from_slice(&buf).unwrap(); // Open the ANM file. - let file = File::open(anm_filename).unwrap(); - let mut file = BufReader::new(file); - let mut buf = vec![]; - file.read_to_end(&mut buf).unwrap(); + let buf = load_file_into_vec(anm_filename); let anm0 = Anm0::from_slice(&buf).unwrap(); // TODO: seed this PRNG with a valid seed.