BiMap

Struct BiMap 

Source
pub struct BiMap<K, V> { /* private fields */ }
Expand description

An ordered, deduplicated collection of key-value pairs with unique values.

Implementations§

Source§

impl<K, V> BiMap<K, V>

Source

pub const fn len(&self) -> usize

Returns the number of entries in the map.

Source

pub const fn is_empty(&self) -> bool

Returns true if the map is empty.

Source

pub fn get(&self, index: usize) -> Option<&K>

Returns a key by index, if it exists.

Source

pub fn position(&self, key: &K) -> Option<usize>
where K: Ord,

Returns the position of the provided key, if it exists.

Source

pub const fn keys(&self) -> &Set<K>

Returns the ordered keys as a Set reference.

Source

pub fn into_keys(self) -> Set<K>

Consumes the map and returns the ordered keys.

Source

pub fn value(&self, index: usize) -> Option<&V>

Returns the associated value at index, if it exists.

Source

pub fn get_value(&self, key: &K) -> Option<&V>
where K: Ord,

Returns the associated value for key, if it exists.

Source

pub fn get_key(&self, value: &V) -> Option<&K>
where V: PartialEq,

Returns the associated key for value, if it exists.

Source

pub fn values(&self) -> &[V]

Returns the associated values.

Source

pub fn iter_pairs(&self) -> impl Iterator<Item = (&K, &V)>

Returns a zipped iterator over keys and values.

Source

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

Returns an iterator over the ordered keys.

Methods from Deref<Target = Set<K>>§

Source

pub fn len(&self) -> usize

Returns the size of the ordered collection.

Source

pub fn is_empty(&self) -> bool

Returns true if the collection is empty.

Source

pub fn get(&self, index: usize) -> Option<&T>

Returns an item by index, if it exists.

Source

pub fn position(&self, item: &T) -> Option<usize>
where T: Ord,

Returns the position of a given item in the collection, if it exists.

Source

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

Returns an iterator over the items in the collection.

Trait Implementations§

Source§

impl<K, V> AsRef<[K]> for BiMap<K, V>

Source§

fn as_ref(&self) -> &[K]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<K, V> AsRef<Set<K>> for BiMap<K, V>

Source§

fn as_ref(&self) -> &Set<K>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<K: Clone, V: Clone> Clone for BiMap<K, V>

Source§

fn clone(&self) -> BiMap<K, V>

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl<K: Debug, V: Debug> Debug for BiMap<K, V>

Source§

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

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

impl<K, V> Default for BiMap<K, V>

Source§

fn default() -> Self

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

impl<K, V> Deref for BiMap<K, V>

Source§

type Target = Set<K>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<K: Display, V: Display> Display for BiMap<K, V>

Source§

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

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

impl<K: EncodeSize, V: EncodeSize> EncodeSize for BiMap<K, V>

Source§

fn encode_size(&self) -> usize

Returns the encoded size of this value (in bytes).
Source§

impl<K, V> From<BiMap<K, V>> for Vec<(K, V)>

Source§

fn from(wrapped: BiMap<K, V>) -> Self

Converts to this type from the input type.
Source§

impl<K: Hash, V: Hash> Hash for BiMap<K, V>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<'a, K, V> IntoIterator for &'a BiMap<K, V>

Source§

type Item = (&'a K, &'a V)

The type of the elements being iterated over.
Source§

type IntoIter = Zip<Iter<'a, K>, Iter<'a, V>>

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<K, V> IntoIterator for BiMap<K, V>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = MapIntoIter<K, V>

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<K: PartialEq, V: PartialEq> PartialEq for BiMap<K, V>

Source§

fn eq(&self, other: &BiMap<K, V>) -> bool

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

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<K: Read + Ord, V: Eq + Hash + Read> Read for BiMap<K, V>

Source§

type Cfg = (RangeCfg<usize>, <K as Read>::Cfg, <V as Read>::Cfg)

The Cfg type parameter allows passing configuration during the read process. This is crucial for safely decoding untrusted data, for example, by providing size limits for collections or strings. Read more
Source§

fn read_cfg(buf: &mut impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Reads a value from the buffer using the provided configuration cfg. Read more
Source§

impl<K: Ord + Clone, V: Clone + Eq + Hash> TryFrom<&[(K, V)]> for BiMap<K, V>

Source§

type Error = Error

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

fn try_from(items: &[(K, V)]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<K: Ord + Clone, V: Clone + Eq + Hash, const N: usize> TryFrom<&[(K, V); N]> for BiMap<K, V>

Source§

type Error = Error

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

fn try_from(items: &[(K, V); N]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<K: Ord, V: Eq + Hash, const N: usize> TryFrom<[(K, V); N]> for BiMap<K, V>

Source§

type Error = Error

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

fn try_from(items: [(K, V); N]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<K, V: Eq + Hash> TryFrom<Map<K, V>> for BiMap<K, V>

Source§

type Error = Error

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

fn try_from(map: Map<K, V>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<K: Ord, V: Eq + Hash> TryFrom<Vec<(K, V)>> for BiMap<K, V>

Source§

type Error = Error

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

fn try_from(items: Vec<(K, V)>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<K: Ord, V: Eq + Hash> TryFromIterator<(K, V)> for BiMap<K, V>

Source§

fn try_from_iter<I: IntoIterator<Item = (K, V)>>( iter: I, ) -> Result<Self, Self::Error>

Attempts to create a BiMap from an iterator of key-value pairs.

Returns an error if any key or value is duplicated.

Source§

type Error = Error

The error type returned when construction fails.
Source§

impl<K: Write, V: Write> Write for BiMap<K, V>

Source§

fn write(&self, buf: &mut impl BufMut)

Writes the binary representation of self to the provided buffer buf. Read more
Source§

impl<K: Eq, V: Eq> Eq for BiMap<K, V>

Source§

impl<K, V> StructuralPartialEq for BiMap<K, V>

Auto Trait Implementations§

§

impl<K, V> Freeze for BiMap<K, V>

§

impl<K, V> RefUnwindSafe for BiMap<K, V>

§

impl<K, V> Send for BiMap<K, V>
where V: Send, K: Send,

§

impl<K, V> Sync for BiMap<K, V>
where V: Sync, K: Sync,

§

impl<K, V> Unpin for BiMap<K, V>
where V: Unpin, K: Unpin,

§

impl<K, V> UnwindSafe for BiMap<K, V>
where V: UnwindSafe, K: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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> Decode for T
where T: Read,

Source§

fn decode_cfg(buf: impl Buf, cfg: &Self::Cfg) -> Result<Self, Error>

Decodes a value from buf using cfg, ensuring the entire buffer is consumed. Read more
Source§

impl<T> Encode for T
where T: Write + EncodeSize,

Source§

fn encode(&self) -> BytesMut

Encodes self into a new BytesMut buffer. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

impl<T> ToString for T
where T: Display + ?Sized,

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Codec for T
where T: Encode + Decode,