/****************************************************************************** * This program demonstrates how to prompt the user for input. * * Copyright © 2020 Richard Lesh. All rights reserved. *****************************************************************************/ mod utils; use std::error; use std::sync::Arc; fn main() { match (|| -> Result<(), Arc>{ let mut favoriteInt:isize = 0; let mut favoriteLong:i64 = 0; let mut favoriteDouble:f64 = 0.0; let mut favoriteIntInput:&str = ""; favoriteIntInput = &(Utils.prompt("What is your favorite small integer? ")); favoriteInt = stoi(favoriteIntInput)?; let mut favoriteLongInput:&str = ""; favoriteLongInput = &(Utils.prompt("What is your favorite large integer? ")); favoriteLong = stol(favoriteLongInput)?; let mut favoriteDoubleInput:&str = ""; favoriteDoubleInput = &(Utils.prompt("What is your favorite floating point? ")); favoriteDouble = stod(favoriteDoubleInput)?; let sum:f64 = (favoriteInt) as f64 + (favoriteLong) as f64 + favoriteDouble; println!("{}", format!("All together they add up to {0:f}!", sum)); return Ok(()); })() { Ok(()) => {}, Err(ex) => { if let Some(ex) = utils::isCustomErrorType(ex.clone(), utils::CustomError::NumberFormatError("".to_string())){ println!("{}", String::from("Bad input! ") + &format!("{}", ex)); } else { println!("Don't know what went wrong!"); } } }; }