• 0 Posts
  • 378 Comments
Joined 1 year ago
cake
Cake day: July 9th, 2023

help-circle














  • // Make optional of type Option<i32>
    let optional = Some(7);
    
    match optional {
        Some(i) => {
            println!("This is a really long string and `{:?}`", i);
            // ^ Needed 2 indentations just so we could destructure
            // `i` from the option.
        },
        _ => {},
        // ^ Required because `match` is exhaustive. Doesn't it seem
        // like wasted space?
    };
    

    I think the rust book gives a good example. The match syntax is just a waste here.

    So if you have a single expression that you want to match I think it is worth it.

    As with most syntax, the more you read it the more you’ll just spot it without thinking.