From 75f9ecb120882652d39b5c4b1ebc0804d35265c2 Mon Sep 17 00:00:00 2001 From: emma Date: Wed, 3 Jul 2024 16:32:47 -0600 Subject: [PATCH] butt(1): code golfed error handling --- fun/butt.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/fun/butt.rs b/fun/butt.rs index 087e70e..889254b 100644 --- a/fun/butt.rs +++ b/fun/butt.rs @@ -5,20 +5,18 @@ // https://www.reddit.com/r/learnpython/comments/17pkw1h/why_wont_my_code_run/ -fn main() { +fn main() -> Result<(), std::num::ParseIntError> { let mut buf = String::new(); println!("How big is your butt?"); let _ = std::io::stdin().read_line(&mut buf); - println!("{}", match buf.trim().parse::() { - Err(_) => { - eprintln!("Your butt can’t be {}!", buf.trim()); - std::process::exit(1); - } - Ok(0..=2) => "Your butt is small Im not gonna smack it ", - Ok(3) => "Your butt is decently sized, if im super horny ill smack and maybe lick it", - Ok(4) => "Your butt is pretty big there, Why don't you come down and ill show it a good time!", + println!("{}", match buf.trim().parse::()? { + 0..=2 => "Your butt is small Im not gonna smack it ", + 3 => "Your butt is decently sized, if im super horny ill smack and maybe lick it", + 4 => "Your butt is pretty big there, Why don't you come down and ill show it a good time!", _ => "WOW Your butt is pretty big! you better pull your pants down RIGHT NOW so i can lick it clean", }); + + Ok(()) }