Structs group named fields. Enums define variants—optionally carrying data. Rust enums are algebraic sum types, richer than C-style enums.
Struct example
struct User { name: String, active: bool }
Enum example
enum Status { Draft, Published }
Self-check
- What keyword defines a product type with fields?
- Can enum variants hold data?
Tuple and unit structs
Tuple structs wrap a single field (struct Meters(f64)) for newtype safety. Unit variants like Option::None model absence without null pointers.
Compare to Go: Rust enums with data replace interface{} + type switches for many API shapes.