Here, dir
is an Option<FlexPath>
, which is printed everytime as Some("/path/to/file")
.
println!("{dir:?}");
let workspace_or_main_dir = workspace_dir.as_ref().unwrap_or(dir.as_ref().unwrap());
// Target path
let target_path = PathBuf::from_str(&workspace_or_main_dir.resolve("target").to_string_with_flex_separator()).unwrap();
// Read the run cache file
let mut run_cache_file: Option<RunCacheFile> = None;
let run_cache_path = PathBuf::from_str(&workspace_or_main_dir.resolve("target/.run-cache.toml").to_string_with_flex_separator()).unwrap();
if std::fs::exists(&run_cache_path).unwrap() && std::fs::metadata(&run_cache_path).unwrap().is_file() {
run_cache_file = Some(toml::from_str::<RunCacheFile>(&std::fs::read_to_string(&run_cache_path).unwrap()).unwrap());
}
if run_cache_file.is_none() {
run_cache_file = Some(RunCacheFile {
packages: vec![]
});
}
let mut run_cache_file = run_cache_file.unwrap();
// Initial lockfile
if lockfile.is_none() {
lockfile = Some(WhackLockfile {
package: vec![]
});
}
let mut lockfile = lockfile.unwrap();
// Current directory (prefer non-workspace directory)
println!("{dir:?}");
let dir = dir.as_ref().unwrap_or(workspace_dir.as_ref().unwrap());
However, in the last .unwrap()
you see it simply panics. Why? It didn't panic the first time we used dir
in the above code region (so it should be Some).