取自current_dir文档的代码片段:
use std::env;
fn main() -> std::io::Result<()> {
let path = env::current_dir()?;
println!("The current directory is {}", path.display());
Ok(())
}
我注意到,仅在 之后添加分号Ok(())
,程序无法编译并出现以下错误:
error[E0308]: mismatched types
expected enum `std::result::Result`, found `()`
这是为什么?