一、let模式匹配
在其它一些语言中,let x = 5 之类的语句,仅仅只是赋值语句。但是在rust中,可以换个角度理解,认为5这个值匹配到了x变量。...另外_在模式匹配中,还可以避免所有权转移:
let s = Some(String::from("hello"));
//由于_不关注值,所以s的所有权不会move到_
if let...("order_id:{} between 0 and 10", x)
}
_ => {}
}
//与上面的写法等效(注意多了1个@符号,表示把匹配到的值...("default"),
}
let t = (2, 3);
match t {
//匹配第1项,第2项放到变量n里
(1, n) => println...("p中的x,y匹配到{},{}", x, y),
_ => println!("others"),
}