enum Message {
Quit,
Move { x: i32, y: i32 },
Write(String),
ChangeColor(i32, i32, i32),
}
fn main() {
let message = Message::Move{x:0, y:10};
match message {
Message::Quit => println!("Quit"),
Message::Move {x,y} => println!("Move(x:{},y:{})", x, y),
Message::Write (s) => println!("Write({})", s),
Message::ChangeColor (r, g, b) => println!("ChangeColor({}, {}, {}", r, g, b),
}
}
Rustのenumとmatch
2022/2/18 19:40:00