Simplify implementation of set_tags()

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

View file

@ -74,14 +74,18 @@ impl Tagable for Value {
} }
fn set_tags(&mut self, ts: &[Tag]) -> Result<()> { fn set_tags(&mut self, ts: &[Tag]) -> Result<()> {
if ts.iter().any(|tag| !is_tag_str(tag).is_ok()) { let _ = ts
let not_tag = ts.iter().filter(|t| !is_tag_str(t).is_ok()).next().unwrap(); .iter()
return Err(format_err!("Not a tag: '{}'", not_tag)); .map(is_tag_str)
} .collect::<Result<Vec<_>>>()?;
let a = ts.iter().unique().map(|t| Value::String(t.clone())).collect(); let header = TagHeader {
debug!("Setting tags = {:?}", a); values: ts.iter().unique().cloned().collect(),
self.insert("tag.values", Value::Array(a)) };
debug!("Setting tags = {:?}", header);
self.get_header_mut()
.insert_serialized("tags", header)
.map(|_| ()) .map(|_| ())
.map_err(|_| Error::from(EM::EntryHeaderWriteError)) .map_err(|_| Error::from(EM::EntryHeaderWriteError))
} }