1
enum FooBar {
Bar,
Foo,
}
struct Whatever {
f_type: FooBar,
}
let what = Whatever { f_type: FooBar::Bar };
我知道這個工程:
let answer: bool = match what {
Whatever { f_type: FooBar::Bar } => true,
_ => false,
};
println!("{:?}", answer); // true
有沒有辦法得到這個工作,使得bar_match
用於比較的價值,而不是被綁定到當前值?
let bar_match = FooBar::Bar;
let answer: bool = match what {
Whatever { f_type: bar_match } => true,
_ => false,
};
println!("{:?}", answer); // true
我是Rust noob,但是我無法在網上找到這個問題的答案。
僅供參考,':bool'是多餘的;該類型是由'match'武器的值推斷的。 – Shepmaster