Handle untrusted input by validating and sanitizing it before use, typically by parsing strings into safe types or using libraries that enforce constraints. In Rust, avoid directly using raw input from std::io::stdin() for logic; instead, parse it with parse() or use crates like validator to ensure safety.
use std::io;
fn main() {
println!("Please input your guess.");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
let guess: u32 = guess.trim().parse()
.expect("Please type a number!");
println!("You guessed: {guess}");
}