PistonDevelopers / input

DEPRECATED - moved into the piston repo
MIT License
7 stars 11 forks source link

`Args` design #25

Closed bvssvni closed 9 years ago

bvssvni commented 10 years ago

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.

pub enum InputEvent {
    KeyPress(KeyPressArgs),
    KeyRelease(KeyReleaseArgs),
    MousePress(MousePressArgs),
    MouseRelease(MouseReleaseArgs),
    ...
}

The arguments has a precise semantics. For example, the MouseMoveArgs contains the mouse position.

bvssvni commented 10 years ago

One drawback with this design is that it does not allow matching against any button press in a single statement.

tomaka commented 10 years ago

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, ..} => (),
    }
}