Reputation: 3666
How do I remove the unused_variables
warning from the following code?
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:
Foo::Bar { a, .. } => // do stuff with 'a'
But I can't find documentation anywhere that explains how to ignore individual struct members.
Upvotes: 12
Views: 5954
Reputation: 432039
I know I can ignore struct members after a certain point with:
The ..
is not positional. It just means "all the other fields":
Foo::Bar { b, .. } => b * b,
Upvotes: 22