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