rustlings

solving rustlings ft. dracuxan
git clone [email protected]:dracuxan/rustlings.git
Log | Files | Refs

enums2.rs (696B)


      1 #[derive(Debug)]
      2 struct Point {
      3     x: u64,
      4     y: u64,
      5 }
      6 
      7 #[derive(Debug)]
      8 enum Message {
      9     // TODO: Define the different variants used below.
     10     Resize { width: i32, height: i32 },
     11     Move(Point),
     12     Echo(String),
     13     ChangeColor(i32, i32, i32),
     14     Quit,
     15 }
     16 
     17 impl Message {
     18     fn call(&self) {
     19         println!("{self:?}");
     20     }
     21 }
     22 
     23 fn main() {
     24     let messages = [
     25         Message::Resize {
     26             width: 10,
     27             height: 30,
     28         },
     29         Message::Move(Point { x: 10, y: 15 }),
     30         Message::Echo(String::from("hello world")),
     31         Message::ChangeColor(200, 255, 255),
     32         Message::Quit,
     33     ];
     34 
     35     for message in &messages {
     36         message.call();
     37     }
     38 }