Simplify implementation of add_tag()

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-06-26 20:14:51 +02:00
parent 061c5beb85
commit e95a4cd15d

View file

@ -91,20 +91,12 @@ impl Tagable for Value {
}
fn add_tag(&mut self, t: Tag) -> Result<()> {
if !is_tag_str(&t).map(|_| true)
.map_err(|s| format_err!("{}", s))
.context(err_msg("Not a tag"))?
{
return Err(format_err!("Not a tag: '{}'", t));
}
let _ = is_tag_str(&t)?;
self.get_tags()
.map(|mut tags| {
let mut tags = self.get_tags()?;
debug!("Pushing tag = {:?} to list = {:?}", t, tags);
tags.push(t);
self.set_tags(&tags.into_iter().unique().collect::<Vec<_>>()[..])
})
.map(|_| ())
self.set_tags(&tags)
}
fn remove_tag(&mut self, t: Tag) -> Result<()> {