Replace match with or_else

This commit is contained in:
Sam Hedin 2020-06-25 17:31:46 +02:00
parent b9c170d359
commit ce23b3b96e
2 changed files with 6 additions and 9 deletions

View File

@ -22,19 +22,16 @@ impl Trusted {
pub fn read_trusted() -> Result<Self, ShellError> {
let config_path = config::default_path_for(&Some(PathBuf::from("nu-env.toml")))?;
let mut file = match std::fs::OpenOptions::new()
let mut file = std::fs::OpenOptions::new()
.read(true)
.create(true)
.write(true)
.open(config_path)
{
Ok(p) => p,
Err(_) => {
return Err(ShellError::untagged_runtime_error(
.or_else(|_| {
Err(ShellError::untagged_runtime_error(
"Couldn't open nu-env.toml",
));
}
};
))
})?;
let mut doc = String::new();
file.read_to_string(&mut doc)?;

View File

@ -49,7 +49,7 @@ impl DirectorySpecificEnvironment {
})?);
}
return Err(ShellError::untagged_runtime_error(
format!("{:?} is untrusted. Run 'autoenv trust {:?}' and restart nushell to trust it.\nThis needs to be done after each change to the file.\n", wdirenv, wdirenv.parent().unwrap_or_else(|| &Path::new("")))));
format!("{:?} is untrusted. Run 'autoenv trust {:?}' and restart nushell to trust it.\nThis needs to be done after each change to the file.", wdirenv, wdirenv.parent().unwrap_or_else(|| &Path::new("")))));
}
Err(ShellError::untagged_runtime_error("No trusted directories"))
}