Use ok_or_else() instead of ok_or()
This commit is contained in:
parent
22170a0d55
commit
f1142c414d
4 changed files with 8 additions and 8 deletions
|
@ -31,7 +31,7 @@ pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bo
|
||||||
let key = "store.implicit-create";
|
let key = "store.implicit-create";
|
||||||
|
|
||||||
if let Some(ref t) = *config {
|
if let Some(ref t) = *config {
|
||||||
t.read_bool(key)?.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))
|
t.read_bool(key)?.ok_or_else(|| SE::from_kind(SEK::ConfigKeyMissingError(key)))
|
||||||
} else {
|
} else {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance {
|
||||||
mtx.get_mut()
|
mtx.get_mut()
|
||||||
.get(&self.absent_path)
|
.get(&self.absent_path)
|
||||||
.cloned()
|
.cloned()
|
||||||
.ok_or(SE::from_kind(SEK::FileNotFound))
|
.ok_or_else(|| SE::from_kind(SEK::FileNotFound))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
|
||||||
.get_mut()
|
.get_mut()
|
||||||
.remove(path)
|
.remove(path)
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
.ok_or(SE::from_kind(SEK::FileNotFound))
|
.ok_or_else(|| SE::from_kind(SEK::FileNotFound))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> {
|
fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> {
|
||||||
|
@ -131,7 +131,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
|
||||||
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
|
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
|
||||||
let backend = mtx.get_mut();
|
let backend = mtx.get_mut();
|
||||||
|
|
||||||
let a = backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))?;
|
let a = backend.get(from).cloned().ok_or_else(|| SE::from_kind(SEK::FileNotFound))?;
|
||||||
backend.insert(to.clone(), a);
|
backend.insert(to.clone(), a);
|
||||||
debug!("Copying: {:?} -> {:?} worked", from, to);
|
debug!("Copying: {:?} -> {:?} worked", from, to);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -142,7 +142,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
|
||||||
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
|
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
|
||||||
let backend = mtx.get_mut();
|
let backend = mtx.get_mut();
|
||||||
|
|
||||||
let a = backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))?;
|
let a = backend.get(from).cloned().ok_or_else(|| SE::from_kind(SEK::FileNotFound))?;
|
||||||
backend.insert(to.clone(), a);
|
backend.insert(to.clone(), a);
|
||||||
debug!("Renaming: {:?} -> {:?} worked", from, to);
|
debug!("Renaming: {:?} -> {:?} worked", from, to);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1007,13 +1007,13 @@ fn has_only_tables(t: &Value) -> Result<bool> {
|
||||||
|
|
||||||
fn has_main_section(t: &Value) -> Result<bool> {
|
fn has_main_section(t: &Value) -> Result<bool> {
|
||||||
t.read("imag")?
|
t.read("imag")?
|
||||||
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag")))
|
.ok_or_else(|| SE::from_kind(SEK::ConfigKeyMissingError("imag")))
|
||||||
.map(Value::is_table)
|
.map(Value::is_table)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_imag_version_in_main_section(t: &Value) -> Result<bool> {
|
fn has_imag_version_in_main_section(t: &Value) -> Result<bool> {
|
||||||
t.read_string("imag.version")?
|
t.read_string("imag.version")?
|
||||||
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))
|
.ok_or_else(|| SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
.map(|s| ::semver::Version::parse(&s).is_ok())
|
.map(|s| ::semver::Version::parse(&s).is_ok())
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ impl StoreId {
|
||||||
.unwrap_or_else(|| self.id.clone())
|
.unwrap_or_else(|| self.id.clone())
|
||||||
.to_str()
|
.to_str()
|
||||||
.map(String::from)
|
.map(String::from)
|
||||||
.ok_or(SE::from_kind(SEK::StoreIdHandlingError))
|
.ok_or_else(|| SE::from_kind(SEK::StoreIdHandlingError))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the components of the `id` part of the StoreId object.
|
/// Returns the components of the `id` part of the StoreId object.
|
||||||
|
|
Loading…
Reference in a new issue