From 702821bbef29c9fe80aba33b595336f59cb7805c Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Sat, 18 Dec 2021 20:08:03 -0500 Subject: [PATCH] added utility file --- src/util.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/util.rs diff --git a/src/util.rs b/src/util.rs new file mode 100644 index 0000000..9691965 --- /dev/null +++ b/src/util.rs @@ -0,0 +1,24 @@ +use std::io; + +// TODO: Can't get this function to properly work +// Currently, I'm grabbing input and have the server tell me whether or +// not input was validated. What I want to have happen is if there's +// a failure in input validation, I want the program to tell right away +// not have the server tell me when I'm doen inputting values +pub fn get_input(question: String) -> String { + let result: String; + loop { + let mut input = String::new(); + println!("{}", &question); + io::stdin().read_line(&mut input).unwrap(); + + match input.len() { + 0 => println!("{}", "Sorry, that wasn't valid input. Please try again.\n"), + _ => { + result = input.trim().to_string(); + break; + } + } + } + result +} \ No newline at end of file