From e95a4cd15d986a35a70bf5caaa500632318aac88 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 26 Jun 2019 20:14:51 +0200 Subject: [PATCH] Simplify implementation of add_tag() Signed-off-by: Matthias Beyer --- lib/entry/libimagentrytag/src/tagable.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/entry/libimagentrytag/src/tagable.rs b/lib/entry/libimagentrytag/src/tagable.rs index b45d2e60..9ca25918 100644 --- a/lib/entry/libimagentrytag/src/tagable.rs +++ b/lib/entry/libimagentrytag/src/tagable.rs @@ -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| { - debug!("Pushing tag = {:?} to list = {:?}", t, tags); - tags.push(t); - self.set_tags(&tags.into_iter().unique().collect::>()[..]) - }) - .map(|_| ()) + let mut tags = self.get_tags()?; + debug!("Pushing tag = {:?} to list = {:?}", t, tags); + tags.push(t); + self.set_tags(&tags) } fn remove_tag(&mut self, t: Tag) -> Result<()> {