From 80ddb740987d535b26e6fe353c127c1a716e598d Mon Sep 17 00:00:00 2001 From: femsci Date: Wed, 28 Dec 2022 14:01:26 +0100 Subject: [PATCH] Argument handling --- src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 820198d..4385cff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,18 @@ const FREQ_TABLE: &[char] = &['f', 'g', 'h', 'j', 'f', 'a', 's', 'd', 'k', 'l', 'g', 'u']; fn main() { - let len = std::env::args().nth(1).unwrap().parse::().unwrap(); + let len: usize = std::env::args() + .nth(1) + .and_then(|x| { + let x = x.parse::(); + if x.is_err() { + eprintln!("Argument is not a number..."); + std::process::exit(-1); + } + Some(x.unwrap()) + }) + .or(Some(32)) + .unwrap(); let mut last: char = '\0';