Skip to main content

FzStringSet

Struct FzStringSet 

Source
pub struct FzStringSet<T, BH = DefaultBuildHasher> { /* private fields */ }
Expand description

A set optimized for fast read access with string values.

A frozen collection differs from the traditional Rust collections, such as HashMap and HashSet types in three key ways. First, creating a frozen collection performs an analysis over the input data to determine the best implementation strategy. Depending on the situation, this analysis is performed at build time or runtime, and it can take a relatively long time when a collection is very large. Second, once created, the keys in frozen collections are immutable. And third, querying a frozen collection is typically considerably faster, which is the whole point.

This type requires that the keys implement the Eq and Hash traits. This can frequently be achieved by using #[derive(PartialEq, Eq, Hash)]. If you implement these yourself, it is important that the following property holds:

k1 == k2 -> hash(k1) == hash(k2)

In other words, if two keys are equal, their hashes must be equal. Violating this property is a logic error.

It is also a logic error for a key to be modified in such a way that the key’s hash, as determined by the Hash trait, or its equality, as determined by the Eq trait, changes while it is in the collection. This is normally only possible through core::cell::Cell, core::cell::RefCell, global state, I/O, or unsafe code.

The behavior resulting from either logic error can include panics, incorrect results, memory leaks, and non-termination.

Implementations§

Source§

impl FzStringSet<Box<str>, DefaultBuildHasher>

Source

pub fn new(entries: Vec<impl AsRef<str>>) -> Self

Creates a new frozen set. If the input contains duplicate value, the latter one in the input is used and all former ones are discarded.

Source§

impl<BH> FzStringSet<Box<str>, BH>

Source

pub fn with_hasher(entries: Vec<impl AsRef<str>>, bh: BH) -> Self
where BH: BuildHasher + Clone + Send + Sync + 'static,

Creates a new frozen set which uses the given hash builder to hash values. If the input contains duplicate value, the latter one in the input is used and all former ones are discarded.

Source§

impl<'a> FzStringSet<&'a str, DefaultBuildHasher>

Source

pub fn new_for_str(entries: Vec<&'a str>) -> Self

Creates a new frozen set. If the input contains duplicate value, the latter one in the input is used and all former ones are discarded.

Source§

impl<'a, BH> FzStringSet<&'a str, BH>

Source

pub fn with_hasher_for_str(entries: Vec<&'a str>, bh: BH) -> Self
where BH: BuildHasher + Clone + Send + Sync + 'static,

Creates a new frozen set which uses the given hash builder to hash values. If the input contains duplicate value, the latter one in the input is used and all former ones are discarded.

Source§

impl<T, BH> FzStringSet<T, BH>

Source

pub fn get(&self, value: impl AsRef<str>) -> Option<&T>
where BH: BuildHasher, str: Equivalent<T>,

Gets a reference to a value in the set.

Source

pub fn contains(&self, value: impl AsRef<str>) -> bool
where BH: BuildHasher, str: Equivalent<T>,

Checks whether a particular value is present in the set.

Source

pub fn len(&self) -> usize

Returns the number of elements in the collection.

Source

pub fn is_empty(&self) -> bool

Returns true if the collection contains no elements.

Source

pub fn iter(&self) -> Iter<'_, T>

An iterator visiting all entries in arbitrary order.

Trait Implementations§

Source§

impl<T, ST, BH> BitAnd<&ST> for &FzStringSet<T, BH>
where T: Hash + Eq + Clone + AsRef<str>, ST: Set<T>, BH: BuildHasher + Default, str: Equivalent<T>,

Source§

type Output = HashSet<T>

The resulting type after applying the & operator.
Source§

fn bitand(self, rhs: &ST) -> Self::Output

Performs the & operation. Read more
Source§

impl<T, ST, BH> BitOr<&ST> for &FzStringSet<T, BH>
where T: Hash + Eq + Clone + AsRef<str>, ST: Set<T>, BH: BuildHasher + Default, str: Equivalent<T>,

Source§

type Output = HashSet<T>

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: &ST) -> Self::Output

Performs the | operation. Read more
Source§

impl<T, ST, BH> BitXor<&ST> for &FzStringSet<T, BH>
where T: Hash + Eq + Clone + AsRef<str>, ST: Set<T>, BH: BuildHasher + Default, str: Equivalent<T>,

Source§

type Output = HashSet<T>

The resulting type after applying the ^ operator.
Source§

fn bitxor(self, rhs: &ST) -> Self::Output

Performs the ^ operation. Read more
Source§

impl<T: Clone, BH: Clone> Clone for FzStringSet<T, BH>

Source§

fn clone(&self) -> FzStringSet<T, BH>

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<T, BH> Debug for FzStringSet<T, BH>
where T: Debug,

Source§

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

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

impl<BH> Default for FzStringSet<&str, BH>
where BH: Default,

Source§

fn default() -> Self

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

impl<BH> Default for FzStringSet<Box<str>, BH>
where BH: Default,

Source§

fn default() -> Self

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

impl<'de, BH> Deserialize<'de> for FzStringSet<Box<str>, BH>
where BH: BuildHasher + Default + Clone + Send + Sync + 'static,

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'a, const N: usize, BH> From<[&'a str; N]> for FzStringSet<&'a str, BH>
where BH: BuildHasher + Default + Clone + Send + Sync + 'static,

Source§

fn from(entries: [&'a str; N]) -> Self

Converts to this type from the input type.
Source§

impl<T, const N: usize, BH> From<[T; N]> for FzStringSet<Box<str>, BH>
where T: AsRef<str>, BH: BuildHasher + Default + Clone + Send + Sync + 'static,

Source§

fn from(entries: [T; N]) -> Self

Converts to this type from the input type.
Source§

impl<T, BH> From<FzStringMap<T, (), BH>> for FzStringSet<T, BH>

Source§

fn from(map: FzStringMap<T, (), BH>) -> Self

Converts to this type from the input type.
Source§

impl<'a, BH> FromIterator<&'a str> for FzStringSet<&'a str, BH>
where BH: BuildHasher + Default + Clone + Send + Sync + 'static,

Source§

fn from_iter<IT: IntoIterator<Item = &'a str>>(iter: IT) -> Self

Creates a value from an iterator. Read more
Source§

impl<T, BH> FromIterator<T> for FzStringSet<Box<str>, BH>
where T: AsRef<str>, BH: BuildHasher + Default + Clone + Send + Sync + 'static,

Source§

fn from_iter<IT: IntoIterator<Item = T>>(iter: IT) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a, T, BH> IntoIterator for &'a FzStringSet<T, BH>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, BH> IntoIterator for FzStringSet<T, BH>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, BH> Len for FzStringSet<T, BH>

Source§

fn len(&self) -> usize

Returns the number of elements in the collection.
Source§

fn is_empty(&self) -> bool

Returns true if the collection contains no elements.
Source§

impl<T, ST, BH> PartialEq<ST> for FzStringSet<T, BH>
where ST: SetQuery<T>, BH: BuildHasher + Default,

Source§

fn eq(&self, other: &ST) -> 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<T, BH> Serialize for FzStringSet<T, BH>
where T: Serialize,

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T, Q, BH> SetExtras<T, Q> for FzStringSet<T, BH>
where Q: AsRef<str>, BH: BuildHasher, str: Equivalent<T>,

Source§

fn get(&self, value: &Q) -> Option<&T>

Gets a reference to a value in the set.
Source§

impl<T, BH> SetIteration<T> for FzStringSet<T, BH>

Source§

type Iterator<'a> = Iter<'a, T> where T: 'a, BH: 'a

The type of the iterator returned by Self::iter.
Source§

fn iter(&self) -> Iter<'_, T>

An iterator visiting all entries in arbitrary order.
Source§

impl<T, Q, BH> SetQuery<Q> for FzStringSet<T, BH>
where Q: AsRef<str>, BH: BuildHasher, str: Equivalent<T>,

Source§

fn contains(&self, value: &Q) -> bool

Checks whether a particular value is present in the set.
Source§

impl<T, ST, BH> Sub<&ST> for &FzStringSet<T, BH>
where T: Hash + Eq + Clone + AsRef<str>, ST: Set<T>, BH: BuildHasher + Default, str: Equivalent<T>,

Source§

type Output = HashSet<T>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &ST) -> Self::Output

Performs the - operation. Read more
Source§

impl<T, BH> Eq for FzStringSet<T, BH>
where T: AsRef<str>, BH: BuildHasher + Default, str: Equivalent<T>,

Source§

impl<T, Q, BH> Set<T, Q> for FzStringSet<T, BH>
where Q: AsRef<str>, BH: BuildHasher, str: Equivalent<T>,

Auto Trait Implementations§

§

impl<T, BH> Freeze for FzStringSet<T, BH>

§

impl<T, BH> RefUnwindSafe for FzStringSet<T, BH>

§

impl<T, BH> Send for FzStringSet<T, BH>
where BH: Send, T: Send,

§

impl<T, BH> Sync for FzStringSet<T, BH>
where BH: Sync, T: Sync,

§

impl<T, BH> Unpin for FzStringSet<T, BH>
where BH: Unpin,

§

impl<T, BH> UnsafeUnpin for FzStringSet<T, BH>

§

impl<T, BH> UnwindSafe for FzStringSet<T, BH>
where BH: UnwindSafe, T: UnwindSafe,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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<ST, T> SetOps<T> for ST
where ST: Set<T>,

Source§

fn union<'a, ST>(&'a self, other: &'a ST) -> Union<'a, Self, ST, T>
where ST: Set<T>, Self: Sized + Set<T>,

Visits the values representing the union, i.e., all the values in self or other, without duplicates.
Source§

fn symmetric_difference<'a, ST>( &'a self, other: &'a ST, ) -> SymmetricDifference<'a, Self, ST, T>
where ST: Set<T>, Self: Sized + Set<T>,

Visits the values representing the symmetric difference, i.e., the values that are in self or in other but not in both.
Source§

fn difference<'a, ST>(&'a self, other: &'a ST) -> Difference<'a, Self, ST, T>
where ST: Set<T>, Self: Sized + Set<T>,

Visits the values representing the difference, i.e., the values that are in self but not in other.
Source§

fn intersection<'a, ST>( &'a self, other: &'a ST, ) -> Intersection<'a, Self, ST, T>
where ST: Set<T>, Self: Sized + Set<T>,

Visits the values representing the intersection, i.e., the values that are both in self and other. Read more
Source§

fn is_disjoint<'a, ST>(&'a self, other: &'a ST) -> bool
where ST: Set<T>, Self: Sized + Set<T>,

Returns true if self has no entries in common with other. This is equivalent to checking for an empty intersection.
Source§

fn is_subset<'a, ST>(&'a self, other: &'a ST) -> bool
where ST: Set<T>, Self: Sized + Set<T>,

Returns true if the set is a subset of another, i.e., other contains at least all the values in self.
Source§

fn is_superset<'a, ST>(&'a self, other: &'a ST) -> bool
where ST: Set<T>, Self: Sized + Set<T>,

Returns true if the set is a superset of another, i.e., self contains at least all the values in other.
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,