Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
对位标志进行典型检查:
if (v & (1 << 0)) != 0 { foo(); } else if (v & (1 << 1)) != 0 { bar(); } else if (v & (1 << 2)) != 0 { baz(); }
这将如何写成match声明?
match
这样的具体代码可以这样重写:
match v.trailing_zeros() { 0 => foo(), 1 => bar(), 2 => baz(), _ => {}, }