I have an enum like:
pub enum Tag<'a> {
Container { c: Vec<Tag<'a>> },
// ...
}
when I try to match:
impl<'a> Display for Tag<'a> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match *self {
Tag::Container { ref c } => write!(f, "{}", "container"),
// ...
}
}
}
I get:
warning: unused variable: `c`, #[warn(unused_variables)] on by default
|
65 | Tag::Container{ref c} => write!(f, "{}", "container"),
and in some other places.
I tried to use _
, just to remove ref c
but it all causes errors.
You can use ..
:
match *self {
Tag::Container { .. } => write!(f, "{}", "container"),
This is covered in the book, specifically under Ignoring bindings where it is used to ignore the values wrapped in an enum variant:
enum OptionalTuple {
Value(i32, i32, i32),
Missing,
}
let x = OptionalTuple::Value(5, -2, 3);
match x {
OptionalTuple::Value(..) => println!("Got a tuple!"),
OptionalTuple::Missing => println!("No such luck."),
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With