You've already forked comprehensive-rust
mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-06-23 17:26:44 +02:00
.github
src
third_party
cxx
rust-by-example
LICENSE-APACHE
LICENSE-MIT
README.md
destructuring-arrays.rs
destructuring-structs.rs
match-guards.rs
webevent.rs
rust-on-exercism
.gitignore
CONTRIBUTING.md
Cargo.toml
LICENSE.txt
README.md
book.toml
ga4.js
rustfmt.toml
25 lines
654 B
Rust
25 lines
654 B
Rust
![]() |
enum WebEvent {
|
||
|
PageLoad, // Variant without payload
|
||
|
KeyPress(char), // Tuple struct variant
|
||
|
Click { x: i64, y: i64 }, // Full struct variant
|
||
|
}
|
||
|
|
||
|
#[rustfmt::skip]
|
||
|
fn inspect(event: WebEvent) {
|
||
|
match event {
|
||
|
WebEvent::PageLoad => println!("page loaded"),
|
||
|
WebEvent::KeyPress(c) => println!("pressed '{c}'"),
|
||
|
WebEvent::Click { x, y } => println!("clicked at x={x}, y={y}"),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn main() {
|
||
|
let load = WebEvent::PageLoad;
|
||
|
let press = WebEvent::KeyPress('x');
|
||
|
let click = WebEvent::Click { x: 20, y: 80 };
|
||
|
|
||
|
inspect(load);
|
||
|
inspect(press);
|
||
|
inspect(click);
|
||
|
}
|