- Published on
- 1 min read
Rust Data Manipulation
Enums
We can think of enum as a collection of named values. Typically these values are called variants.
Enum variants can be accessed by using the enum name and the variant name.
Looking at the example below we can access the
Color
enum and the Red
variant
using the ::
operator to access the Red
variant.enum Color{
Red,
Green,
Blue,
}
fn main() {
let red = Color::Red;
let green = Color::Green;
let bue = Color::Blue;
}
Structs
struct User {
username: String,
age: i32
}
Tuples
let drink = ("coke", 1.50);
let (drink_name, drink_price) = drink;
Expressions
let gt_ten = 10 > 5;