mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-02-02 23:38:41 +08:00
20 lines
602 B
Rust
20 lines
602 B
Rust
fn main() {
|
|
let favorite_color: Option<&str> = None;
|
|
let is_tuesday = false;
|
|
let age: Result<u8, _> = "34".parse();
|
|
|
|
if let Some(color) = favorite_color {
|
|
println!("Using your favorite color, {}, as the background", color);
|
|
} else if is_tuesday {
|
|
println!("Tuesday is green day!");
|
|
} else if let Ok(age) = age {
|
|
if age > 30 {
|
|
println!("Using purple as the background color");
|
|
} else {
|
|
println!("Using orange as the background color");
|
|
}
|
|
} else {
|
|
println!("Using blue as the background color");
|
|
}
|
|
}
|