Add Is::set_isflag() helper function

This commit is contained in:
Matthias Beyer 2018-01-03 17:03:09 +01:00
parent a246144c26
commit a7c8fa1212

View file

@ -22,6 +22,7 @@ use error::Result;
use toml::Value; use toml::Value;
use toml_query::read::TomlValueReadExt; use toml_query::read::TomlValueReadExt;
use toml_query::insert::TomlValueInsertExt;
/// Trait to check whether an entry is a certain kind of entry /// Trait to check whether an entry is a certain kind of entry
/// ///
@ -68,6 +69,7 @@ use toml_query::read::TomlValueReadExt;
/// ///
pub trait Is { pub trait Is {
fn is<T: IsKindHeaderPathProvider>(&self) -> Result<bool>; fn is<T: IsKindHeaderPathProvider>(&self) -> Result<bool>;
fn set_isflag<T: IsKindHeaderPathProvider>(&mut self) -> Result<()>;
} }
impl Is for ::libimagstore::store::Entry { impl Is for ::libimagstore::store::Entry {
@ -81,6 +83,13 @@ impl Is for ::libimagstore::store::Entry {
Err(e) => Err(EUE::from(e)) Err(e) => Err(EUE::from(e))
} }
} }
fn set_isflag<T: IsKindHeaderPathProvider>(&mut self) -> Result<()> {
self.get_header_mut()
.insert(T::kindflag_header_location(), Value::Boolean(true))
.map_err(EUE::from)
.map(|_| ())
}
} }