It uses .. to ignore the value, while I have only seen _ to do that so far, so is there any semantic difference in matching x and y in the following code example?
enum OptInt {
Value(i32),
Missing,
}
fn main() {
let x = OptInt::Value(5);
let y = OptInt::Value(5);
match x {
OptInt::Value(..) => println!("Got an int!"),
OptInt::Missing => println!("No such luck."),
}
match y {
OptInt::Value(_) => println!("Got an int!"),
OptInt::Missing => println!("No such luck."),
}
}
You can use _ as a placeholder for exactly one field, but .. can elide an arbitrary number of fields. For example, if your enum had Pair(i32, i32), you could match Pair(_, _) or Pair(..).