Skip to content

Match Expressions

Match expressions provide powerful pattern matching capabilities.

let status := 200;
match status {
200 => io::Println("OK"),
404 => io::Println("Not Found"),
500 => io::Println("Server Error"),
_ => io::Println("Unknown Status"),
}

Match expressions return values:

let message := match status {
200 => "Success",
404 => "Not Found",
_ => "Error",
};
type Status enum {
Pending,
Active,
Done,
};
let status := Status::Active;
match status {
Status::Pending => io::Println("Waiting"),
Status::Active => io::Println("In Progress"),
Status::Done => io::Println("Complete"),
}