changeset 1:4adea0a8c8dd

Remove all unwraps.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 19 Nov 2020 21:36:00 +0100
parents 57b200fad67e
children 1a2852861d8b
files src/main.rs
diffstat 1 files changed, 10 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/main.rs
+++ b/src/main.rs
@@ -125,38 +125,38 @@ fn main() -> Result<(), Box<dyn Error>> 
     let output_filename = &args[4];
 
     let vxseek = {
-        let mut vxseek = File::open(vxseek_filename).unwrap();
+        let mut vxseek = File::open(vxseek_filename)?;
         let mut contents = String::new();
-        vxseek.read_to_string(&mut contents).unwrap();
-        parse_vxseek(&contents).unwrap()
+        vxseek.read_to_string(&mut contents)?;
+        parse_vxseek(&contents)?
     };
     {
-        let vxvideo = File::open(vxvideo_filename).unwrap();
+        let vxvideo = File::open(vxvideo_filename)?;
         let mut vxvideo = BufReader::new(vxvideo);
 
-        let output = File::create(output_filename).unwrap();
+        let output = File::create(output_filename)?;
         let mut output = BufWriter::new(output);
 
         let mut name: Option<String> = None;
         for VxSeekLine { timestamp, video_name, codec, resolution, unknown, length } in vxseek {
             if let Some(ref name) = &name {
                 if &video_name != name {
-                    vxvideo.seek(SeekFrom::Current(length as i64)).unwrap();
+                    vxvideo.seek(SeekFrom::Current(length as i64))?;
                     continue;
                 }
             } else {
                 if resolution != wanted_resolution {
                     println!("Skipping {} due to resolution {}", video_name, resolution);
-                    vxvideo.seek(SeekFrom::Current(length as i64)).unwrap();
+                    vxvideo.seek(SeekFrom::Current(length as i64))?;
                     continue;
                 }
                 name = Some(video_name);
             }
             let mut buf = Vec::with_capacity(length as usize);
             unsafe { buf.set_len(length as usize) };
-            vxvideo.read_exact(&mut buf).unwrap();
-            output.write_all(&buf).unwrap();
-            output.flush().unwrap();
+            vxvideo.read_exact(&mut buf)?;
+            output.write_all(&buf)?;
+            output.flush()?;
         }
     }
     Ok(())