changeset 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 eab7dde1164f
children a662dddd4a2b
files examples/anmrenderer.rs examples/common.rs examples/eclrenderer.rs examples/stagerunner.rs examples/stdrenderer.rs
diffstat 5 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/examples/anmrenderer.rs
+++ b/examples/anmrenderer.rs
@@ -107,7 +107,7 @@ fn main() {
     let script: u8 = args[2].parse().expect("number");
 
     // Open the ANM file.
-    let buf = load_file_into_vec(anm_filename);
+    let buf = load_file_into_vec(anm_filename).unwrap();
     let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
     let anm0 = anms.pop().unwrap();
 
--- 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 {
--- a/examples/eclrenderer.rs
+++ b/examples/eclrenderer.rs
@@ -101,11 +101,11 @@ fn main() {
     let sub: u16 = args[4].parse().expect("number");
 
     // Open the ECL file.
-    let buf = load_file_into_vec(ecl_filename);
+    let buf = load_file_into_vec(ecl_filename).unwrap();
     let (_, ecl) = Ecl::from_slice(&buf).unwrap();
 
     // Open the ANM file.
-    let buf = load_file_into_vec(anm_filename);
+    let buf = load_file_into_vec(anm_filename).unwrap();
     let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
     let anm0 = anms.pop().unwrap();
     let anm0 = Rc::new(RefCell::new([anm0.clone(), anm0]));
--- a/examples/stagerunner.rs
+++ b/examples/stagerunner.rs
@@ -100,20 +100,20 @@ fn main() {
     let rank: Rank = args[3].parse().expect("rank");
 
     // Open the ECL file.
-    let buf = load_file_into_vec(directory.join(format!("ecldata{}.ecl", stage_number)));
+    let buf = load_file_into_vec(directory.join(format!("ecldata{}.ecl", stage_number))).unwrap();
     let (_, ecl) = Ecl::from_slice(&buf).unwrap();
     assert_eq!(ecl.mains.len(), 1);
     let main = ecl.mains[0].clone();
 
     // Open the ANM file.
     let anm_filename = directory.join(format!("stg{}enm.anm", stage_number));
-    let buf = load_file_into_vec(&anm_filename);
+    let buf = load_file_into_vec(&anm_filename).unwrap();
     let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
     let anm0 = anms.pop().unwrap();
 
     // Open the second ANM file.
     let anm2_filename = directory.join(format!("stg{}enm2.anm", stage_number));
-    let buf = load_file_into_vec(&anm2_filename);
+    let buf = load_file_into_vec(&anm2_filename).unwrap();
     let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
     let anm0_bis = anms.pop().unwrap();
 
--- a/examples/stdrenderer.rs
+++ b/examples/stdrenderer.rs
@@ -118,11 +118,11 @@ fn main() {
     let anm_filename = Path::new(&args[2]);
 
     // Open the STD file.
-    let buf = load_file_into_vec(std_filename);
+    let buf = load_file_into_vec(std_filename).unwrap();
     let (_, stage) = Stage::from_slice(&buf).unwrap();
 
     // Open the ANM file.
-    let buf = load_file_into_vec(anm_filename);
+    let buf = load_file_into_vec(anm_filename).unwrap();
     let (_, mut anms) = Anm0::from_slice(&buf).unwrap();
     let anm0 = anms.pop().unwrap();