Closed bvssvni closed 9 years ago
One drawback with this design is that it does not allow matching against any button press in a single statement.
Instead of using this, I would suggest using the struct_variant
feature instead.
For example:
#![feature(struct_variant)]
pub enum Event {
KeyPress {
pub key: int,
pub something: int,
},
KeyRelease {
pub key: int,
pub something: int,
},
}
fn foo(ev: &Event) {
match ev {
&KeyPress{ref key, ..} => (),
&KeyRelease{ref something, ..} => (),
}
}
Notice: This design is not used!
This design is inspired by Windows.Forms in C#, but made more powerful by using Rust's enum type. The idea is to separate the arguments from the enum declaration of the event.
The arguments has a precise semantics. For example, the
MouseMoveArgs
contains the mouse position.