Skip to main content

Matches

Struct Matches 

Source
pub struct Matches { /* private fields */ }
Expand description

Match set.

This match set implementation is based on a minimal bitset implementation, that allows to efficiently manage and work with match sets and filters. It mustn’t be considered a complete implementation of general purpose bitsets, but only provides the methods we need for efficient matching.

Using a focused implementation allows us to optimize for our specific use case, and avoids yet another dependency to manage.

Implementations§

Source§

impl Matches

Source

pub fn new() -> Self

Creates a match set.

§Examples
use zrx_id::Matches;

// Create match set
let matches = Matches::new();
Source

pub fn with_capacity(capacity: usize) -> Self

Creates a match set with the given capacity.

§Examples
use zrx_id::Matches;

// Create match set with capacity
let matches = Matches::with_capacity(128);
Source

pub fn contains(&self, index: usize) -> bool

Returns whether the match set contains the given match.

§Panics

Panics if the index is out of bounds.

§Examples
use zrx_id::Matches;

// Create match set
let matches = Matches::from_iter([1]);

// Ensure presence of matches
assert_eq!(matches.contains(0), false);
assert_eq!(matches.contains(1), true);
Source

pub fn add(&mut self, index: usize)

Adds a match to the match set.

§Examples
use zrx_id::Matches;

// Create match set
let mut matches = Matches::new();

// Add match to set
matches.add(0);
Source

pub fn clear(&mut self)

Clears all matches in the match set.

§Examples
use zrx_id::Matches;

// Create match set
let mut matches = Matches::from_iter([0, 1, 2]);

// Remove all matches
matches.clear();
assert!(matches.is_empty());
Source

pub fn union(&mut self, other: &Self)

Computes the union with the given match set.

§Examples
use zrx_id::Matches;

// Create two match sets
let mut a = Matches::from_iter([0, 1]);
let mut b = Matches::from_iter([1, 2]);

// Create union of match sets
a.union(&b);
assert_eq!(a, Matches::from_iter([0, 1, 2]));
Source

pub fn intersect(&mut self, other: &Self)

Computes the intersection with the given match set.

§Examples
use zrx_id::Matches;

// Create two match sets
let mut a = Matches::from_iter([0, 1]);
let mut b = Matches::from_iter([1, 2]);

// Create intersection of match sets
a.intersect(&b);
assert_eq!(a, Matches::from_iter([1]));
Source

pub fn has_any(&self, other: &Self) -> bool

Returns whether any of the given matches is present.

§Examples
use zrx_id::Matches;

// Create two match sets
let mut a = Matches::from_iter([0, 1]);
let mut b = Matches::from_iter([1, 2]);

// Ensure presence of matches
assert!(b.has_any(&a));
Source

pub fn has_all(&self, other: &Self) -> bool

Returns whether the given matches are all present.

§Examples
use zrx_id::Matches;

// Create two match sets
let mut a = Matches::from_iter([0, 1]);
let mut b = Matches::from_iter([0, 1, 2]);

// Ensure presence of matches
assert!(b.has_all(&a));
Source§

impl Matches

Source

pub fn len(&self) -> usize

Returns the number of matches.

Source

pub fn is_empty(&self) -> bool

Returns whether there are any matches.

Trait Implementations§

Source§

impl Clone for Matches

Source§

fn clone(&self) -> Matches

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
Source§

impl Debug for Matches

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Matches

Source§

fn default() -> Self

Creates a match set.

§Examples
use zrx_id::Matches;

// Create match set
let matches = Matches::default();
Source§

impl FromIterator<usize> for Matches

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = usize>,

Creates a match set from an iterator.

§Examples
use zrx_id::Matches;

// Create match set from iterator
let matches = Matches::from_iter([0, 1]);
Source§

impl IntoIterator for Matches

Source§

fn into_iter(self) -> Self::IntoIter

Creates a consuming iterator over the match set.

§Examples
use zrx_id::Matches;

// Create match set from iterator
let mut matches = Matches::from_iter([0, 1]);

// Create iterator over match set
for index in matches {
    println!("{index:?}");
}
Source§

type Item = usize

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

impl PartialEq for Matches

Source§

fn eq(&self, other: &Matches) -> 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.
Source§

impl Eq for Matches

Source§

impl StructuralPartialEq for Matches

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<K, V> TryAsStorage<K> for V
where K: Key, V: Value,

Source§

fn try_as_storage( item: &(dyn Any + 'static), ) -> Result<<V as TryAsStorage<K>>::Target<'_>, Error>

Attempts to convert into a storage reference.

§Errors

The following errors might be returned:

§Examples
use std::any::Any;
use zrx_storage::convert::TryAsStorage;
use zrx_storage::Storage;

// Create storage and initial state
let mut storage = Storage::default();
storage.insert("key", 42);

// Obtain type-erased reference
let item: &dyn Any = &storage;

// Obtain storage reference
let storage = <i32>::try_as_storage(item)?;
Source§

type Target<'a> = &'a Storage<K, V>

Target type of conversion.
Source§

impl<K, V> TryAsStorageMut<K> for V
where K: Key, V: Value,

Source§

fn try_as_storage_mut( item: &mut (dyn Any + 'static), ) -> Result<<V as TryAsStorageMut<K>>::Target<'_>, Error>

Attempts to convert into a mutable storage reference.

§Errors

The following errors might be returned:

§Examples
use std::any::Any;
use zrx_storage::convert::TryAsStorageMut;
use zrx_storage::Storage;

// Create storage and initial state
let mut storage = Storage::default();
storage.insert("key", 42);

// Obtain mutable type-erased reference
let item: &mut dyn Any = &mut storage;

// Obtain mutable storage reference
let storage = <i32>::try_as_storage_mut(item)?;
Source§

type Target<'a> = &'a mut Storage<K, V>

Target type of conversion.
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.
Source§

impl<T> Value for T
where T: Debug + Eq + 'static,