I want to use an if let
to unwrap an Option
while only entering the block if a certain condition is met as well.
What I came up with to solve this was the following:
fn main() {
let number = 15; // Set any number for testing
let option: Option<&str> = Option::Some("test");
if let (true, Some(text)) = (number >= 10, option) {
println!("{}", text);
}
}
Is this the 'correct' way to handle this situation or is there a better, intended way to solve it without having the if let
inside another if
?
Aucun commentaire:
Enregistrer un commentaire