libimaghabit: Replace read with typed read

This commit is contained in:
Matthias Beyer 2018-01-12 16:31:41 +01:00
parent 46774d765b
commit f2b72f4738
3 changed files with 6 additions and 8 deletions

View file

@ -18,7 +18,7 @@
// //
use toml::Value; use toml::Value;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
use toml_query::insert::TomlValueInsertExt; use toml_query::insert::TomlValueInsertExt;
use chrono::NaiveDateTime; use chrono::NaiveDateTime;
use chrono::Local; use chrono::Local;
@ -217,9 +217,9 @@ impl HabitTemplate for Entry {
fn habit_until_date(&self) -> Result<Option<String>> { fn habit_until_date(&self) -> Result<Option<String>> {
self.get_header() self.get_header()
.read("habit.template.until")? .read_string("habit.template.until")
.map(|v| v.as_str().map(String::from)) .map_err(From::from)
.ok_or(HEK::HeaderTypeError("habit.template.until", "String").into()) .map(|os| os.map(String::from))
} }
fn instance_id_for(habit_name: &String, habit_date: &NaiveDate) -> Result<StoreId> { fn instance_id_for(habit_name: &String, habit_date: &NaiveDate) -> Result<StoreId> {

View file

@ -19,7 +19,6 @@
use chrono::NaiveDate; use chrono::NaiveDate;
use toml::Value; use toml::Value;
use toml_query::read::TomlValueReadExt;
use toml_query::set::TomlValueSetExt; use toml_query::set::TomlValueSetExt;
use error::*; use error::*;

View file

@ -93,11 +93,10 @@ impl IsHabitCheck for Entry {
#[inline] #[inline]
pub fn get_string_header_from_entry(e: &Entry, path: &'static str) -> Result<String> { pub fn get_string_header_from_entry(e: &Entry, path: &'static str) -> Result<String> {
use error::HabitErrorKind as HEK; use error::HabitErrorKind as HEK;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadTypeExt;
e.get_header() e.get_header()
.read(path)? .read_string(path)?
.ok_or(HEK::HeaderFieldMissing(path).into()) .ok_or(HEK::HeaderFieldMissing(path).into())
.and_then(|o| o.as_str().map(String::from).ok_or(HEK::HeaderTypeError(path, "String").into()))
} }