Hello guys, I wish to make a tiny command-line app that takes input from a user, checks if that String exists in an array, and then returns "User found" if the String exists and "Not found" if the String doesn't exist in that array.
Right now, I'm doing this :
use std::io;
fn main() {
println!("Enter your name :");
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Failed to read line");
if input.to_string().contains("Andy") {
println!("User found!")
}
else if input.to_string().contains("John") {
println!("User found!")
}
else {
println!("Sorry, user not found!")
}
}
My aim is rather than checking each in a separate if block, it be checked from this array:
let array = vec!["Andy", "John"];
Thanks.