Enums
https://doc.rust-lang.org/reference/items/enumerations.html
Option, which you have likely seen all over Rust code, is not a struct - it's an enum, with two variants. Enums resemble algebraic sum types found in functional programming languages:
#![allow(unused)] fn main() { enum Option<T> { None, Some(T), } impl<T> Option<T> { fn unwrap(self) -> T { // enums variants can be used in patterns: match self { Self::Some(t) => t, Self::None => panic!(".unwrap() called on a None option"), } } } }
Result is also an enum, it can either contain something, or an error:
#![allow(unused)] fn main() { enum Result<T, E> { Ok(T), Err(E), } }
It also panics when unwrapped and containing an error.