Struct TagPredicate
pub struct TagPredicate { /* private fields */ }Expand description
A validated conjunction of required/all, optional/any and excluded/none tags.
Every required query must match, at least one optional query must match when
that clause is nonempty, and no excluded query may match. All clauses use
TagSet::matches hierarchy and case rules. An empty clause imposes no
restriction, so Self::default matches every set, including an empty set.
In particular, an empty optional clause differs from
TagSet::matches_any with an empty slice, which returns false.
Each clause owns at most 256 distinct queries of at most 128 ASCII bytes,
using the same validation and duplicate handling as TagSet::insert.
Contradictory clauses are allowed and simply never match; exclusions always
veto a match, even when a required or optional query also matches.
Construction can allocate; matching does not allocate or mutate either value.
use ferravex_engine::tags::{TagError, TagPredicate, TagSet};
let predicate = TagPredicate::default().with_all(&["render.mesh"])?;
let mut tags = TagSet::default();
tags.insert("render.mesh.animated")?;
assert!(predicate.matches(&tags));
assert_eq!(
TagPredicate::default().with_none(&["state..hidden"]),
Err(TagError::Invalid),
);Implementations§
§impl TagPredicate
impl TagPredicate
pub fn with_all(self, queries: &[&str]) -> Result<TagPredicate, TagError>
pub fn with_all(self, queries: &[&str]) -> Result<TagPredicate, TagError>
Replace the required clause: every query must match.
Other clauses are preserved. An empty slice clears this restriction. Repeated calls replace rather than append queries.
§Errors
Returns TagError::Invalid for a malformed query, or
TagError::Capacity when there are more than 256 distinct queries.
use ferravex_engine::tags::{TagError, TagPredicate, TagSet};
let predicate = TagPredicate::default().with_all(&["actor", "team.blue"])?;
let mut tags = TagSet::default();
tags.insert("actor.player")?;
assert!(!predicate.matches(&tags));
tags.insert("team.blue")?;
assert!(predicate.matches(&tags));pub fn with_any(self, queries: &[&str]) -> Result<TagPredicate, TagError>
pub fn with_any(self, queries: &[&str]) -> Result<TagPredicate, TagError>
Replace the optional alternatives: at least one query must match.
Other clauses are preserved. An empty slice clears this restriction, allowing sets with no tags to pass this clause. Repeated calls replace rather than append alternatives.
§Errors
Returns TagError::Invalid for a malformed query, or
TagError::Capacity when there are more than 256 distinct queries.
use ferravex_engine::tags::{TagError, TagPredicate, TagSet};
let predicate = TagPredicate::default().with_any(&["team.blue", "team.red"])?;
let mut tags = TagSet::default();
assert!(!predicate.matches(&tags));
tags.insert("team.red.player")?;
assert!(predicate.matches(&tags));pub fn with_none(self, queries: &[&str]) -> Result<TagPredicate, TagError>
pub fn with_none(self, queries: &[&str]) -> Result<TagPredicate, TagError>
Replace the excluded clause: no query may match.
Other clauses are preserved. An empty slice clears this restriction. Repeated calls replace rather than append queries.
§Errors
Returns TagError::Invalid for a malformed query, or
TagError::Capacity when there are more than 256 distinct queries.
use ferravex_engine::tags::{TagError, TagPredicate, TagSet};
let predicate = TagPredicate::default().with_none(&["state.hidden"])?;
let mut tags = TagSet::default();
assert!(predicate.matches(&tags));
tags.insert("state.hidden.cloaked")?;
assert!(!predicate.matches(&tags));pub fn matches(&self, tags: &TagSet) -> bool
pub fn matches(&self, tags: &TagSet) -> bool
Match all three clauses against a tag set without allocating.
use ferravex_engine::tags::{TagError, TagPredicate, TagSet};
let predicate = TagPredicate::default()
.with_all(&["actor"])?
.with_none(&["state.dead"])?;
let mut tags = TagSet::default();
tags.insert("actor.enemy")?;
assert!(predicate.matches(&tags));
tags.insert("state.dead")?;
assert!(!predicate.matches(&tags));Trait Implementations§
§impl Clone for TagPredicate
impl Clone for TagPredicate
§fn clone(&self) -> TagPredicate
fn clone(&self) -> TagPredicate
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more