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

View File

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

View File

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