RBE custom types enum
This commit is contained in:
parent
90f6fdad97
commit
5d0811636f
33
rustbyexample/custom_types/custom_types_enum.rs
Normal file
33
rustbyexample/custom_types/custom_types_enum.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
enum WebEvent {
|
||||||
|
PageLoad,
|
||||||
|
PageUnload,
|
||||||
|
KeyPress(char),
|
||||||
|
Paste(String),
|
||||||
|
Click { x: i64, y: i64 },
|
||||||
|
}
|
||||||
|
|
||||||
|
fn inspect(event: WebEvent) {
|
||||||
|
match event {
|
||||||
|
WebEvent::PageLoad => println!("page loaded"),
|
||||||
|
WebEvent::PageUnload => println!("page unloaded"),
|
||||||
|
WebEvent::KeyPress(c) => println!("pressed '{}'.", c),
|
||||||
|
WebEvent::Paste(s) => println!("pasted \"{}\".", s),
|
||||||
|
WebEvent::Click { x, y } => {
|
||||||
|
println!("clicked at x={}, y={}.", x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let pressed = WebEvent::KeyPress('x');
|
||||||
|
let pasted = WebEvent::Paste("my text".to_owned());
|
||||||
|
let click = WebEvent::Click { x: 20, y: 80 };
|
||||||
|
let load = WebEvent::PageLoad;
|
||||||
|
let unload = WebEvent::PageUnload;
|
||||||
|
|
||||||
|
inspect(pressed);
|
||||||
|
inspect(pasted);
|
||||||
|
inspect(click);
|
||||||
|
inspect(load);
|
||||||
|
inspect(unload);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user