diff options
Diffstat (limited to 'src/doc/book/listings/ch18-patterns-and-matching/listing-18-01/src/main.rs')
-rw-r--r-- | src/doc/book/listings/ch18-patterns-and-matching/listing-18-01/src/main.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch18-patterns-and-matching/listing-18-01/src/main.rs b/src/doc/book/listings/ch18-patterns-and-matching/listing-18-01/src/main.rs new file mode 100644 index 000000000..fc87768fb --- /dev/null +++ b/src/doc/book/listings/ch18-patterns-and-matching/listing-18-01/src/main.rs @@ -0,0 +1,19 @@ +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, {color}, as the background"); + } 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"); + } +} |