如果我.to_path_buf()之后立即调用expect,则不会创建临时目录.这是一个bug还是Rust功能?
extern crate mktemp;
use std::path::Path;
fn main() {
let temp_dir = mktemp::Temp::new_dir().expect("Failed to create a temp directory");
let temp_dir_path = temp_dir.to_path_buf();
println!("tmp path exists: {}", Path::exists(&temp_dir_path));
let temp_dir_path = mktemp::Temp::new_dir().expect("Failed to create a temp directory").to_path_buf();
println!("tmp path exists: {}", Path::exists(&temp_dir_path));
}
Run Code Online (Sandbox Code Playgroud)
哪个输出:
tmp path exists: true
tmp path exists: false
Run Code Online (Sandbox Code Playgroud)