1
我想,而不調用它們都匹配多個函數的結果,如果沒有必要:如何在模式匹配時避免多餘的函數調用?
fn foo() -> bool {
println!("foo executed");
true
}
// I want to do something like this
// but there is a redundant function call
match (foo(), foo()) {
(false, true) => println!("Bingo!"),
_ => println!("Wrong result"),
}
// No redundant function call
// but less impressive and doubling of wrong result processing
match foo() {
false => match foo() {
true => println!("Bingo"),
_ => println!("Wrong result"),
},
_ => println!("Wrong result"),
}
我怎樣才能做到這一點?