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"),
}
我怎样才能做到这一点?