[英]How to ignore a member of a struct-like enum variant in pattern matching?
How do I remove the unused_variables
warning from the following code? 如何从以下代码中删除
unused_variables
警告?
pub enum Foo {
Bar {
a: i32,
b: i32,
c: i32,
},
Baz,
}
fn main() {
let myfoo = Foo::Bar { a: 1, b: 2, c: 3 };
let x: i32 = match myfoo {
Foo::Bar { a, b, c } => b * b,
Foo::Baz => -1,
};
assert_eq!(x, 4);
}
I know I can ignore struct members after a certain point with: 我知道我可以在某一点之后忽略struct成员:
Foo::Bar { a, .. } => // do stuff with 'a'
But I can't find documentation anywhere that explains how to ignore individual struct members. 但我无法在任何地方找到解释如何忽略单个struct成员的文档。
I know I can ignore struct members after a certain point with:
我知道我可以在某一点之后忽略struct成员:
The ..
is not positional. ..
不是位置的。 It just means "all the other fields": 它只是意味着“所有其他领域”:
Foo::Bar { b, .. } => b * b,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.