Simplify implementation of has_tag()
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
87bfb422dc
commit
59bea23004
1 changed files with 2 additions and 14 deletions
|
@ -108,20 +108,8 @@ impl Tagable for Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_tag(&self, t: TagSlice) -> Result<bool> {
|
fn has_tag(&self, t: TagSlice) -> Result<bool> {
|
||||||
let tags = self.read("tag.values").context(EM::EntryHeaderReadError)?;
|
// use any() because Vec::contains() wants &String, but we do not want to allocate.
|
||||||
|
self.get_tags().map(|v| v.iter().any(|s| s == t))
|
||||||
if !tags.iter().all(|t| is_match!(*t, &Value::String(_))) {
|
|
||||||
return Err(err_msg("Tag type error"))
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(tags
|
|
||||||
.iter()
|
|
||||||
.any(|tag| {
|
|
||||||
match *tag {
|
|
||||||
&Value::String(ref s) => { s == t },
|
|
||||||
_ => unreachable!()
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_tags(&self, tags: &[Tag]) -> Result<bool> {
|
fn has_tags(&self, tags: &[Tag]) -> Result<bool> {
|
||||||
|
|
Loading…
Reference in a new issue