23.04 Structs and Enums
Structs and Enums
Overview
Structs and enums are used to define custom data types in Rust.
Topics
- Defining and Using Structs
- Tuple Structs
- Enums with Variants
Examples
struct Point {
x: i32,
y: i32,
}
let p = Point { x: 10, y: 20 };
println!("Point: ({}, {})", p.x, p.y);
enum Direction {
Up,
Down,
Left,
Right,
}
let dir = Direction::Up;
match dir {
Direction::Up => println!("Going up"),
_ => println!("Other direction"),
}