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