Removed all remaining unwrap() and expect() functions from main.rs

They now make use of the messages.rs error messages.
This commit is contained in:
Dennis Potter 2018-07-27 23:43:24 +02:00
parent 1e7907358f
commit 6e05947498
2 changed files with 29 additions and 10 deletions

View File

@ -85,9 +85,18 @@ fn main() {
(0x413d , 0x2107)
];
info!("Initializing HidApi. This can take a moment.");
info!("Initializing HID object. This can take a moment.");
let api = match hidapi::HidApi::new() {
Ok(res) => {
info!("Succesfully initialized HID object.");
res
},
Err(_) => {
error!("Could not initialize HID object.")
},
};
let api = hidapi::HidApi::new().expect("Hidapi init failed!");
let mut dev_path = String::new();
for device in &api.devices() {
@ -99,8 +108,15 @@ fn main() {
}
}
let dev = api.open_path(dev_path.as_str()).unwrap();
let dev = match api.open_path(dev_path.as_str()) {
Ok(res) => {
info!("Succesfully opened device.");
res
},
Err(_) => {
error!("Could not open device. Make sure your device is connected. Maybe try to reconnect it.")
},
};
// All options that need the device to be open

View File

@ -18,15 +18,18 @@ macro_rules! warning {
#[macro_export]
macro_rules! error {
($($arg:tt)*) => {
{
eprintln!("{:7}{}", "Error".on_red().white(), format_args!($($arg)*));
println!("");
process::exit(0);
}
};
}
pub fn welcome(string: &str) {
println!("{}", "".repeat(string.len() + 2));
println!("{text:^-width$}", text = string, width = string.len() + 2);
println!("{}", "".repeat(string.len() + 2));
println!("{}", "".repeat(string.len() + 20));
println!("{text:^-width$}", text = string, width = string.len() + 20);
println!("{}", "".repeat(string.len() + 20));
}
pub fn goodbye() {