Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum Message {
- Quit,
- Move { x: i32, y: i32 },
- Write(String),
- ChangeColor(i32, i32, i32),
- }
- impl std::fmt::Display for Message {
- fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
- match self {
- Message::Quit => write!(f, "Quit"),
- Message::Move { x, y } => write!(f, "Move to [{}, {}]", x, y),
- Message::Write(s) => write!(f, "{}", s),
- Message::ChangeColor(r, g, b) => write!(f, "r: {}, g: {}, b: {}", r, g, b),
- }
- }
- }
- fn main() {
- println!("{}", Message::Quit);
- println!("{}", Message::Move { x: 5, y: 10 });
- println!("{}", Message::Write(std::string::String::from("Hello")));
- println!("{}", Message::ChangeColor(255, 0, 0));
- }
Add Comment
Please, Sign In to add comment