0
如何獲得match
語句中通配符臂的值?獲取通配符臂的值
例如:
let a = 1i;
let b = 2i;
match a.cmp(&b) {
Greater => println!("is greater"),
_ => println!("is {}", _) // error: unexpected token: `_`
}
我希望的東西不是存儲enum
在一個變量被匹配清潔:
let a = 1i;
let b = 2i;
let ord = a.cmp(&b);
match ord {
Greater => println!("is greater"),
_ => println!("is {}", ord)
}
謝謝,不知道任何標識符可以用作通配符。 – August 2014-10-19 16:15:58
是的,但有一個問題可以解決:如果您嘗試在不使用'use'導入的'enum'變體上匹配,您可能會得到[關於無法訪問的模式的錯誤](http://is.gd/ Dep83r)。在這裏,'Greater'是自動導入的,因爲它是前奏的一部分。 – 2014-10-19 17:48:56