Assignment from Rust match statement
问题 Is there an idiom in Rust which is used to assign the value of a variable based on a match clause? I know something like val b = a match { case x if x % 2 == 1 => false case _ => true } from Scala and was wondering whether you can do the same in Rust. Is there a way to evaluate a match clause as an expression and return something from it or is it just a statement in Rust? 回答1: In Rust, nearly every statement is also an expression. You can do this: fn main() { let a = 3; let b = match a { x if