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	Tue Feb 25 19:37:19 2020 +0100
+++ b/examples/anmrenderer.rs	Wed Jan 29 17:45:25 2020 +0100
@@ -107,7 +107,7 @@
     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	Tue Feb 25 19:37:19 2020 +0100
+++ b/examples/common.rs	Wed Jan 29 17:45:25 2020 +0100
@@ -4,15 +4,15 @@
 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	Tue Feb 25 19:37:19 2020 +0100
+++ b/examples/eclrenderer.rs	Wed Jan 29 17:45:25 2020 +0100
@@ -101,11 +101,11 @@
     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	Tue Feb 25 19:37:19 2020 +0100
+++ b/examples/stagerunner.rs	Wed Jan 29 17:45:25 2020 +0100
@@ -100,20 +100,20 @@
     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	Tue Feb 25 19:37:19 2020 +0100
+++ b/examples/stdrenderer.rs	Wed Jan 29 17:45:25 2020 +0100
@@ -118,11 +118,11 @@
     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();