dont panic, rather return errors in main
[Mitarbeiter/Tim-Zeitz/stud-rust-base.git] / src / bin / decode_vector.rs
index 180804b..691a7a0 100644 (file)
@@ -1,43 +1,43 @@
 extern crate stud_rust_base;
-use stud_rust_base::io::*;
-use std::env;
+use stud_rust_base::{io::*, cli::CliErr};
+use std::{env, error::Error};
 
-fn main() {
+fn main() -> Result<(), Box<dyn Error>> {
     let mut args = env::args();
     args.next();
 
     match &args.collect::<Vec<String>>()[..] {
         [data_type, input] => {
             match data_type.as_ref() {
-                "i8" => print_values(Vec::<i8>::load_from(input).expect("Failed to read from input")),
-                "u8" => print_values(Vec::<u8>::load_from(input).expect("Failed to read from input")),
-                "i16" => print_values(Vec::<i16>::load_from(input).expect("Failed to read from input")),
-                "u16" => print_values(Vec::<u16>::load_from(input).expect("Failed to read from input")),
-                "i32" => print_values(Vec::<i32>::load_from(input).expect("Failed to read from input")),
-                "u32" => print_values(Vec::<u32>::load_from(input).expect("Failed to read from input")),
-                "i64" => print_values(Vec::<i64>::load_from(input).expect("Failed to read from input")),
-                "u64" => print_values(Vec::<u64>::load_from(input).expect("Failed to read from input")),
-                "f32" => print_values(Vec::<f32>::load_from(input).expect("Failed to read from input")),
-                "f64" => print_values(Vec::<f64>::load_from(input).expect("Failed to read from input")),
-                "int8" => print_values(Vec::<i8>::load_from(input).expect("Failed to read from input")),
-                "uint8" => print_values(Vec::<u8>::load_from(input).expect("Failed to read from input")),
-                "int16" => print_values(Vec::<i16>::load_from(input).expect("Failed to read from input")),
-                "uint16" => print_values(Vec::<u16>::load_from(input).expect("Failed to read from input")),
-                "int32" => print_values(Vec::<i32>::load_from(input).expect("Failed to read from input")),
-                "uint32" => print_values(Vec::<u32>::load_from(input).expect("Failed to read from input")),
-                "int64" => print_values(Vec::<i64>::load_from(input).expect("Failed to read from input")),
-                "uint64" => print_values(Vec::<u64>::load_from(input).expect("Failed to read from input")),
-                "float32" => print_values(Vec::<f32>::load_from(input).expect("Failed to read from input")),
-                "float64" => print_values(Vec::<f64>::load_from(input).expect("Failed to read from input")),
+                "i8" => { print_values(Vec::<i8>::load_from(input)?); Ok(()) },
+                "u8" => { print_values(Vec::<u8>::load_from(input)?); Ok(()) },
+                "i16" => { print_values(Vec::<i16>::load_from(input)?); Ok(()) },
+                "u16" => { print_values(Vec::<u16>::load_from(input)?); Ok(()) },
+                "i32" => { print_values(Vec::<i32>::load_from(input)?); Ok(()) },
+                "u32" => { print_values(Vec::<u32>::load_from(input)?); Ok(()) },
+                "i64" => { print_values(Vec::<i64>::load_from(input)?); Ok(()) },
+                "u64" => { print_values(Vec::<u64>::load_from(input)?); Ok(()) },
+                "f32" => { print_values(Vec::<f32>::load_from(input)?); Ok(()) },
+                "f64" => { print_values(Vec::<f64>::load_from(input)?); Ok(()) },
+                "int8" => { print_values(Vec::<i8>::load_from(input)?); Ok(()) },
+                "uint8" => { print_values(Vec::<u8>::load_from(input)?); Ok(()) },
+                "int16" => { print_values(Vec::<i16>::load_from(input)?); Ok(()) },
+                "uint16" => { print_values(Vec::<u16>::load_from(input)?); Ok(()) },
+                "int32" => { print_values(Vec::<i32>::load_from(input)?); Ok(()) },
+                "uint32" => { print_values(Vec::<u32>::load_from(input)?); Ok(()) },
+                "int64" => { print_values(Vec::<i64>::load_from(input)?); Ok(()) },
+                "uint64" => { print_values(Vec::<u64>::load_from(input)?); Ok(()) },
+                "float32" => { print_values(Vec::<f32>::load_from(input)?); Ok(()) },
+                "float64" => { print_values(Vec::<f64>::load_from(input)?); Ok(()) },
                 _ => {
                     print_usage();
-                    panic!("Unknown data_type {}", data_type);
+                    Err(Box::new(CliErr("Invalid data type")))
                 }
-            };
+            }
         },
         _ => {
             print_usage();
-            panic!("Invalid input")
+            Err(Box::new(CliErr("Invalid arguments")))
         },
     }
 }