我正在阅读一些Rust代码,我遇到了这一行
if let Some(path) = env::args().nth(1) {
Run Code Online (Sandbox Code Playgroud)
在这个功能里面
fn main() {
if let Some(path) = env::args().nth(1) {
// Try reading the file provided by the path.
let mut file = File::open(path).expect("Failed reading file.");
let mut content = String::new();
file.read_to_string(&mut content);
perform_conversion(content.as_str()).expect("Conversion failed.");
} else {
println!(
"provide a path to a .cue file to be converted into a MusicBrainz compatible tracklist."
)
}
}
Run Code Online (Sandbox Code Playgroud)
该行似乎是将env参数分配给变量路径,但我无法弄清楚Some()它周围正在做什么.
我看了一下文档Option,我理解它在右侧使用时是如何工作的=但是在左侧我有点困惑.
我是否认为这条线相当于
if let path = Some(env::args().nth(1)) …Run Code Online (Sandbox Code Playgroud)