Home 16. Option/Result match?!
Post
Cancel

16. Option/Result match?!

Try to avoid matching Option or Result.

Use if let instead.

1
2
3
4
5
6
7
8
9
10
11
12
13
let result = Some(111);

// Not nice
match result {
    Some(x) => println!("{x}"),
    None => {}
};

// Better
if let Some(x) = result {
    println!("{x}");
}

This post is licensed under CC BY 4.0 by the author.