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