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
impl Matches
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a match set.
§Examples
use zrx_id::Matches;
// Create match set
let matches = Matches::new();Sourcepub fn with_capacity(capacity: usize) -> Self
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);Sourcepub fn contains(&self, index: usize) -> bool
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);Sourcepub fn add(&mut self, index: usize)
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);Sourcepub fn clear(&mut self)
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());Sourcepub fn union(&mut self, other: &Self)
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]));Sourcepub fn intersect(&mut self, other: &Self)
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]));Trait Implementations§
Source§impl FromIterator<usize> for Matches
impl FromIterator<usize> for Matches
Source§impl IntoIterator for Matches
impl IntoIterator for Matches
impl Eq for Matches
impl StructuralPartialEq for Matches
Auto Trait Implementations§
impl Freeze for Matches
impl RefUnwindSafe for Matches
impl Send for Matches
impl Sync for Matches
impl Unpin for Matches
impl UnsafeUnpin for Matches
impl UnwindSafe for Matches
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<K, V> TryAsStorage<K> for V
impl<K, V> TryAsStorage<K> for V
Source§fn try_as_storage(
item: &(dyn Any + 'static),
) -> Result<<V as TryAsStorage<K>>::Target<'_>, Error>
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:
Error::Downcast: Item cannot be downcast.
§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§impl<K, V> TryAsStorageMut<K> for V
impl<K, V> TryAsStorageMut<K> for V
Source§fn try_as_storage_mut(
item: &mut (dyn Any + 'static),
) -> Result<<V as TryAsStorageMut<K>>::Target<'_>, Error>
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:
Error::Downcast: Item cannot be downcast.
§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)?;