我意识到 Rust 在不断变化,但无论如何我都在努力学习它。我试图了解如何将以下适用于 0.9 的示例改编为适用于 0.10 的类似示例:
fn main() {
let argv = std::os::args();
let (first, last) = match argv {
[_, first_arg, .., last_arg] => (first_arg, last_arg),
_ => fail!("Error: At least two arguments expected.")
};
println!("The first argument was {:s}, \
and the last argument was {:s}.", first, last);
}
当我用 0.10 构建它时,我收到以下错误:
error: couldn't read test.rc: no such file or directory (No such file or directory)
orflongpmacx8:rust pohl_longsine$ rustc test.rs
test.rs:9:9: 9:37 error: unique vector patterns are no longer supported
test.rs:9 [_, first_arg, .., last_arg] => (first_arg, last_arg),
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error
我的问题:是否仍然可以在 argv 上使用模式匹配,但使用不同的语法,或者根本不再可能在 argv 上使用 match 语句?如果是前者,我需要改变什么?