Hi there! Today, instead of writing another python program, I had wrote a rust program. In this code, the goal was to ask for user’s name and then reply back.
Requirements:
- Ask for user name
- Replies back with ‘Hi, {name}, nice to meet you!’
The code:
use std::io;
fn main() {
println!("What is your name?");
// Let's variable 'name' become mutable
let mut name = String::new();
match io::stdin().read_line(&mut name) {
Ok(_) => {
//trims the string
let trim1 = name.trim();
println!("Hi {}, nice to meet you.", trim1);
},
Err(error) => println!("error: {error}"),
}
}
That’s all! Hehehe. Bai bai.