Pretty simple:
let x = A(EventOne { x: 0.1, y: 0.1 }, ~"Hello");
match x {
A(EventOne{x, y}, s) => println!("{}, {}, {}", x, y, s),
B(EventTwo{x, y}, s) => println!("{}, {}, {}", x, y, s)
}
Note that matching like this means that you are moving out ~str
field because it is not implicitly copyable, so x
becomes partially moved value, which you cannot use further. If you do want to use the value after the match, you can bind s
by reference:
let x = B(EventTwo { x: 1, y: 2 }, ~"World");
match x {
A(EventOne{x, y}, ref s) => println!("{}, {}, {}", x, y, *s),
B(EventTwo{x, y}, ref s) => println!("{}, {}, {}", x, y, *s)
}
In this case s
has type &~str
, so you have to dereference it to print it. You will be able to use x
afterwards, because you are not moving ~str
field out, and the other field is implicitly copyable because it consists of implicitly copyable data.