Enum

enum Message {
    Quit,
    Move { x: i32, y: i32 },
    Write(String),
    ChangeColor(i32, i32, i32),
}
 
fn process(&mut self, message: Message) {
    match message {
        Message::ChangeColor((r, g, b)) => self.change_color((r, g, b)),
        Message::Echo(s) => self.echo(s),
        Message::Move(p) => self.move_position(p),
        Message::Quit => self.quit()
    }
}
 
  • Quit has no data associated with it at all.
  • Move has named fields like a struct does.
  • Write includes a single String.
  • ChangeColor includes three i32 values.

Vector

let v: Vec<i32> = Vec::new(); //empty
let v = vec![1, 2, 3]; // or
v.push(5);
v.push(6);
v.push(7);
v.push(8);

Strings

Hash Maps

use std::collections::HashMap
basket.entry(Fruit::Banana).or_insert(50); // Adding a Key and Value Only If a Key Isn’t Present