[No-auto] lib/domain/habit: Fix Clippy warnings

Signed-off-by: flip1995 <hello@philkrones.com>
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
flip1995 2019-08-27 10:20:46 +02:00 committed by Matthias Beyer
parent 2ac2a86c7a
commit 6307b80027

View file

@ -90,7 +90,7 @@ pub trait HabitTemplate : Sized {
fn instance_exists_for_date(&self, date: NaiveDate) -> Result<bool>; fn instance_exists_for_date(&self, date: NaiveDate) -> Result<bool>;
/// Create a StoreId for a habit name and a date the habit should be instantiated for /// Create a StoreId for a habit name and a date the habit should be instantiated for
fn instance_id_for(habit_name: &String, habit_date: NaiveDate) -> Result<StoreId>; fn instance_id_for(habit_name: &str, habit_date: NaiveDate) -> Result<StoreId>;
} }
provide_kindflag_path!(pub IsHabitTemplate, "habit.template.is_habit_template"); provide_kindflag_path!(pub IsHabitTemplate, "habit.template.is_habit_template");
@ -164,7 +164,7 @@ impl HabitTemplate for Entry {
.calculate()? .calculate()?
.get_moment() .get_moment()
.map(Clone::clone) .map(Clone::clone)
.ok_or_else(|| Error::from(err_msg("until-date seems to have non-date value"))) .ok_or_else(|| err_msg("until-date seems to have non-date value"))
}); });
debug!("Until-Date is {:?}", basedate); debug!("Until-Date is {:?}", basedate);
@ -177,7 +177,7 @@ impl HabitTemplate for Entry {
if ndt >= base { if ndt >= base {
debug!("-> {:?} >= {:?}", ndt, base); debug!("-> {:?} >= {:?}", ndt, base);
if let Some(u) = until { if let Some(u) = until {
if ndt > &(u?) { if *ndt > u? {
return Ok(None); return Ok(None);
} else { } else {
return Ok(Some(ndt.date())); return Ok(Some(ndt.date()));
@ -249,13 +249,13 @@ impl HabitTemplate for Entry {
Ok(false) Ok(false)
} }
fn instance_id_for(habit_name: &String, habit_date: NaiveDate) -> Result<StoreId> { fn instance_id_for(habit_name: &str, habit_date: NaiveDate) -> Result<StoreId> {
instance_id_for_name_and_datestr(habit_name, &date_to_string(habit_date)) instance_id_for_name_and_datestr(habit_name, &date_to_string(habit_date))
} }
} }
fn instance_id_for_name_and_datestr(habit_name: &String, habit_date: &String) -> Result<StoreId> { fn instance_id_for_name_and_datestr(habit_name: &str, habit_date: &str) -> Result<StoreId> {
crate::module_path::new_id(format!("instance/{}-{}", habit_name, habit_date)) crate::module_path::new_id(format!("instance/{}-{}", habit_name, habit_date))
.context(format_err!("Failed building ID for instance: habit name = {}, habit date = {}", habit_name, habit_date)) .context(format_err!("Failed building ID for instance: habit name = {}, habit date = {}", habit_name, habit_date))
.map_err(Error::from) .map_err(Error::from)
@ -318,7 +318,7 @@ pub mod builder {
pub fn build<'a>(self, store: &'a Store) -> Result<FileLockEntry<'a>> { pub fn build<'a>(self, store: &'a Store) -> Result<FileLockEntry<'a>> {
#[inline] #[inline]
fn mkerr(s: &'static str) -> Error { fn mkerr(s: &'static str) -> Error {
Error::from(format_err!("Habit builder missing: {}", s)) format_err!("Habit builder missing: {}", s)
} }
let name = self.name let name = self.name
@ -336,7 +336,7 @@ pub mod builder {
if let Some(until) = self.untildate { if let Some(until) = self.untildate {
debug!("Success: Until-Date present"); debug!("Success: Until-Date present");
if dateobj > until { if dateobj > until {
let e = Error::from(err_msg("Habit builder logic error: until-date before start date")); let e = err_msg("Habit builder logic error: until-date before start date");
return Err(e); return Err(e);
} }
} }
@ -348,13 +348,13 @@ pub mod builder {
let date = date_to_string(dateobj); let date = date_to_string(dateobj);
debug!("Success: Date valid"); debug!("Success: Date valid");
let comment = self.comment.unwrap_or_else(|| String::new()); let comment = self.comment.unwrap_or_else(String::new);
let sid = build_habit_template_sid(&name)?; let sid = build_habit_template_sid(&name)?;
debug!("Creating entry in store for: {:?}", sid); debug!("Creating entry in store for: {:?}", sid);
let mut entry = store.create(sid)?; let mut entry = store.create(sid)?;
let _ = entry.set_isflag::<IsHabitTemplate>()?; entry.set_isflag::<IsHabitTemplate>()?;
{ {
let h = entry.get_header_mut(); let h = entry.get_header_mut();
let _ = h.insert("habit.template.name", Value::String(name))?; let _ = h.insert("habit.template.name", Value::String(name))?;
@ -387,7 +387,7 @@ pub mod builder {
} }
/// Buld a StoreId for a Habit from a date object and a name of a habit /// Buld a StoreId for a Habit from a date object and a name of a habit
fn build_habit_template_sid(name: &String) -> Result<StoreId> { fn build_habit_template_sid(name: &str) -> Result<StoreId> {
crate::module_path::new_id(format!("template/{}", name)).map_err(From::from) crate::module_path::new_id(format!("template/{}", name)).map_err(From::from)
} }
@ -400,7 +400,7 @@ fn postprocess_instance<'a>(mut entry: FileLockEntry<'a>,
-> Result<FileLockEntry<'a>> -> Result<FileLockEntry<'a>>
{ {
{ {
let _ = entry.set_isflag::<IsHabitInstance>()?; entry.set_isflag::<IsHabitInstance>()?;
let hdr = entry.get_header_mut(); let hdr = entry.get_header_mut();
let _ = hdr.insert("habit.instance.name", Value::String(name))?; let _ = hdr.insert("habit.instance.name", Value::String(name))?;
let _ = hdr.insert("habit.instance.date", Value::String(date))?; let _ = hdr.insert("habit.instance.date", Value::String(date))?;