Take a typical check for bit-flags:
if (v & (1 << 0)) != 0 { foo(); }
else if (v & (1 << 1)) != 0 { bar(); }
else if (v & (1 << 2)) != 0 { baz(); }
How would this be written as a match
statement?
Take a typical check for bit-flags:
if (v & (1 << 0)) != 0 { foo(); }
else if (v & (1 << 1)) != 0 { bar(); }
else if (v & (1 << 2)) != 0 { baz(); }
How would this be written as a match
statement?
if (v & (1 << 0)) != 0 { foo(); }
else if (v & (1 << 1)) != 0 { bar(); }
else if (v & (1 << 2)) != 0 { baz(); }
Such concrete code can be rewritten like this:
match v.trailing_zeros() {
0 => foo(),
1 => bar(),
2 => baz(),
_ => {},
}