From 3ef5fcfab6e779791086ac8d3add8bc73b26d2a5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 12 Jan 2018 16:31:13 +0100 Subject: [PATCH] libimagstore: Replace read with typed read --- lib/core/libimagstore/src/configuration.rs | 7 ++----- lib/core/libimagstore/src/store.rs | 12 +++++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/lib/core/libimagstore/src/configuration.rs b/lib/core/libimagstore/src/configuration.rs index b1b1974e..813a3289 100644 --- a/lib/core/libimagstore/src/configuration.rs +++ b/lib/core/libimagstore/src/configuration.rs @@ -26,15 +26,12 @@ use error::StoreErrorKind as SEK; /// Checks whether the store configuration has a key "implicit-create" which maps to a boolean /// value. If that key is present, the boolean is returned, otherwise false is returned. pub fn config_implicit_store_create_allowed(config: &Option) -> Result { - use toml_query::read::TomlValueReadExt; + use toml_query::read::TomlValueReadTypeExt; let key = "store.implicit-create"; if let Some(ref t) = *config { - t.read(key)? - .ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))? - .as_bool() - .ok_or(SE::from_kind(SEK::ConfigTypeError(key, "boolean"))) + t.read_bool(key)?.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key))) } else { Ok(false) } diff --git a/lib/core/libimagstore/src/store.rs b/lib/core/libimagstore/src/store.rs index a547e0ce..9a41e75c 100644 --- a/lib/core/libimagstore/src/store.rs +++ b/lib/core/libimagstore/src/store.rs @@ -36,6 +36,7 @@ use glob::glob; use walkdir::WalkDir; use walkdir::Iter as WalkDirIter; use toml_query::read::TomlValueReadExt; +use toml_query::read::TomlValueReadTypeExt; use error::{StoreError as SE, StoreErrorKind as SEK}; use error::ResultExt; @@ -1102,13 +1103,10 @@ fn has_main_section(t: &Value) -> Result { } fn has_imag_version_in_main_section(t: &Value) -> Result { - use toml_query::read::TomlValueReadExt; - - t.read("imag.version")? - .ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))? - .as_str() - .map(|s| ::semver::Version::parse(s).is_ok()) - .ok_or(SE::from_kind(SEK::ConfigTypeError("imag.version", "String"))) + t.read_string("imag.version")? + .ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version"))) + .map(String::from) + .map(|s| ::semver::Version::parse(&s).is_ok()) }