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

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>

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>

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

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

§

fn clone(&self) -> TagPredicate

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for TagPredicate

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for TagPredicate

§

fn default() -> TagPredicate

Returns the “default value” for a type. Read more
§

impl PartialEq for TagPredicate

§

fn eq(&self, other: &TagPredicate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Eq for TagPredicate

§

impl StructuralPartialEq for TagPredicate

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.