jam_types

Struct VecMap

Source
pub struct VecMap<K, V>(/* private fields */);
Expand description

An mapping of key/value pairs stored as pairs ordered by their key in a Vec.

This is always efficient for small sizes of mappings, and efficient for large sizes when insertion is not needed (i.e. items are placed into the mapping in bulk).

Implementations§

Source§

impl<K: Eq + PartialEq + Ord + PartialOrd, V> VecMap<K, V>

Source

pub fn new() -> Self

Create a new, empty instance.

Source

pub fn from_sorted(v: Vec<(K, V)>) -> Result<Self, ()>

Create a new instance from a sorted Vec.

Returns Ok with an instance containing the same items as v, or Err if v is unsorted.

Source

pub fn len(&self) -> usize

Return the number of items this mapping contains.

Source

pub fn is_empty(&self) -> bool

Return true if this mapping is empty.

Source

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

Return an iterator over the key/value pairs in this mapping in order.

Source

pub fn keys(&self) -> impl Iterator<Item = &K>

Return an iterator over the keys in this mapping in order.

Source

pub fn values(&self) -> impl Iterator<Item = &V>

Return an iterator over the values in this mapping in order of their corresponding key.

Source

pub fn get(&self, k: &K) -> Option<&V>

Get the value of the pair with a particular key.

Returns a reference the value of the item in the mapping whose key equals k.

Source

pub fn get_mut(&mut self, k: &K) -> Option<&mut V>

Get a mutable reference to the value of the pair with a particular key.

Returns a mutable reference the value of the item in the mapping whose key equals k.

Source

pub fn map<U>(self, f: impl FnMut(K, V) -> U) -> Vec<U>

Consume this mapping and return a Vec of transformed pairs.

Returns the Vec of the resultant values of applying f to each pair in the mapping in order.

Source

pub fn map_ref<U>(&self, f: impl FnMut(&K, &V) -> U) -> Vec<U>

Transform all pairs by reference and return a Vec with the results.

Returns the Vec of the resultant values of applying f to each pair by reference in the mapping in order.

Source

pub fn to_vec(&self) -> Vec<(K, V)>
where K: Clone, V: Clone,

Return a Vec of sorted key/value pairs by cloning this mapping.

Source

pub fn into_vec(self) -> Vec<(K, V)>

Return the Vec of sorted key/value pairs by consuming this mapping.

Source

pub fn insert(&mut self, k: K, v: V) -> Option<(K, V)>

Insert pair into the mapping.

Inserts some pair (k, v) into the mapping, replacing the existing pair whose key is k, if any.

Returns Some value which was replaced, if any.

NOTE: This does an ordered insert and thus is slow. If you’re inserting multiple items, use Self::extend which is much more efficient or consider using an alternative data structure if you’re doing this a lot.

Source

pub fn extend(&mut self, iter: impl IntoIterator<Item = (K, V)>)

Insert multiple pairs from an iterator.

Replaces any existing pairs which share a key with an element of the iterator.

Source

pub fn contains_key(&self, k: &K) -> bool

Check if a key is in the mapping.

Returns true iff the mapping contains a pair whose key equals k.

Source

pub fn remove(&mut self, k: &K) -> Option<(K, V)>

Remove an item from the mapping by key.

Removes the item with key equal to k from the mapping.

Returns the value of the item removed, if any.

Source

pub fn retain(&mut self, f: impl FnMut(&K, &V) -> bool)

Filter items from the mapping.

Removes all pairs from the mapping for which f returns false.

Source

pub fn is_disjoint(&self, other: &VecMap<K, V>) -> bool
where V: Ord,

Compares the pairs in two mappings.

Returns true iff every pair in the mapping is not found in other.

Source

pub fn keys_disjoint<W>(&self, other: &VecMap<K, W>) -> bool

Compares the keys in two mappings.

Returns true iff every key in the mapping is not found in the keys of other.

Source

pub fn keys_disjoint_with_set(&self, other: &VecSet<K>) -> bool

Compares the keys in this mapping with the values in a set.

Returns true iff every key in the mapping is not found in other.

Trait Implementations§

Source§

impl<K, V> AsMut<[(K, V)]> for VecMap<K, V>

Source§

fn as_mut(&mut self) -> &mut [(K, V)]

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

impl<K, V> AsRef<[(K, V)]> for VecMap<K, V>

Source§

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

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

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

Source§

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

Returns a copy 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<K: Debug, V: Debug> Debug for VecMap<K, V>

Source§

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

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

impl<K: Decode + Eq + PartialEq + Ord + PartialOrd, V: Decode> Decode for VecMap<K, V>

Source§

fn decode<I: Input>(input: &mut I) -> Result<Self, DecodeError>

Attempt to deserialise the value from input.
Source§

fn decode_into<I>( input: &mut I, dst: &mut MaybeUninit<Self>, ) -> Result<DecodeFinished, Error>
where I: Input,

Attempt to deserialize the value from input into a pre-allocated piece of memory. Read more
Source§

fn skip<I>(input: &mut I) -> Result<(), Error>
where I: Input,

Attempt to skip the encoded value from input. Read more
Source§

fn encoded_fixed_size() -> Option<usize>

Returns the fixed encoded size of the type. Read more
Source§

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

Source§

fn default() -> Self

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

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

Source§

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

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

impl<K, V> Encode for VecMap<K, V>
where Vec<(K, V)>: Encode,

Source§

fn size_hint(&self) -> usize

If possible give a hint of expected size of the encoding. Read more
Source§

fn encode_to<__CodecOutputEdqy: Output + ?Sized>( &self, __codec_dest_edqy: &mut __CodecOutputEdqy, )

Convert self to a slice and append it to the destination.
Source§

fn encode(&self) -> Vec<u8>

Convert self to an owned vector.
Source§

fn using_encoded<__CodecOutputReturn, __CodecUsingEncodedCallback: FnOnce(&[u8]) -> __CodecOutputReturn>( &self, f: __CodecUsingEncodedCallback, ) -> __CodecOutputReturn

Convert self to a slice and then invoke the given closure with it.
Source§

fn encoded_size(&self) -> usize

Calculates the encoded size. Read more
Source§

impl<K: Eq + PartialEq + Ord + PartialOrd, V> Extend<(K, V)> for VecMap<K, V>

Source§

fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<K: Eq + PartialEq + Ord + PartialOrd, V> From<Vec<(K, V)>> for VecMap<K, V>

Source§

fn from(v: Vec<(K, V)>) -> Self

Converts to this type from the input type.
Source§

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

Source§

fn from(s: VecMap<K, V>) -> Vec<(K, V)>

Converts to this type from the input type.
Source§

impl<K: Eq + PartialEq + Ord + PartialOrd, V> FromIterator<(K, V)> for VecMap<K, V>

Source§

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

Creates a value from an iterator. Read more
Source§

impl<K: Eq + PartialEq + Ord + PartialOrd, V> IntoIterator for VecMap<K, V>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = <Vec<(K, V)> as IntoIterator>::IntoIter

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: Eq + PartialEq + Ord + PartialOrd, V> MapLike<K, V> for VecMap<K, V>

Source§

fn insert(&mut self, k: K, v: V) -> Option<V>

Insert pair into the mapping. Read more
Source§

fn extend(&mut self, iter: impl Iterator<Item = (K, V)>)

Insert multiple pairs from an iterator. Read more
Source§

fn contains_key(&self, k: &K) -> bool

Check if a key is in the mapping. Read more
Source§

fn remove(&mut self, k: &K) -> Option<V>

Remove an item from the mapping by key. Read more
Source§

fn get(&self, k: &K) -> Option<&V>

Get the value of the pair with a particular key. Read more
Source§

fn get_mut(&mut self, k: &K) -> Option<&mut V>

Get a mutable reference to the value of the pair with a particular key. Read more
Source§

fn keys<'a>(&'a self) -> impl Iterator<Item = &'a K>
where K: 'a,

Get an iterator to all keys in the mapping. Read more
Source§

impl<K: Ord, V: Ord> Ord for VecMap<K, V>

Source§

fn cmp(&self, other: &VecMap<K, V>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<K: PartialEq, V: PartialEq> PartialEq for VecMap<K, V>

Source§

fn eq(&self, other: &VecMap<K, V>) -> 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<K: PartialOrd, V: PartialOrd> PartialOrd for VecMap<K, V>

Source§

fn partial_cmp(&self, other: &VecMap<K, V>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<K, V> EncodeLike for VecMap<K, V>
where Vec<(K, V)>: Encode,

Source§

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

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<K, V> UnwindSafe for VecMap<K, V>
where K: UnwindSafe, V: 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, U> AsByteSlice<T> for U
where T: ToByteSlice, U: AsRef<[T]> + ?Sized,

Source§

fn as_byte_slice(&self) -> &[u8]

Source§

impl<T, U> AsMutByteSlice<T> for U
where T: ToMutByteSlice, U: AsMut<[T]> + ?Sized,

Source§

fn as_mut_byte_slice(&mut self) -> &mut [u8]

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, dst: *mut u8)

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

impl<T> DecodeAll for T
where T: Decode,

Source§

fn decode_all(input: &mut &[u8]) -> Result<T, Error>

Decode Self and consume all of the given input data. Read more
Source§

impl<T> DecodeLimit for T
where T: Decode,

Source§

fn decode_all_with_depth_limit( limit: u32, input: &mut &[u8], ) -> Result<T, Error>

Decode Self and consume all of the given input data. Read more
Source§

fn decode_with_depth_limit<I>(limit: u32, input: &mut I) -> Result<T, Error>
where I: Input,

Decode Self with the given maximum recursion depth and advance input by the number of bytes consumed. 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> KeyedVec for T
where T: Codec,

Source§

fn to_keyed_vec(&self, prepend_key: &[u8]) -> Vec<u8>

Return an encoding of Self prepended by given slice.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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<S> Codec for S
where S: Decode + Encode,

Source§

impl<T> EncodeLike<&&T> for T
where T: Encode,

Source§

impl<T> EncodeLike<&T> for T
where T: Encode,

Source§

impl<T> EncodeLike<&mut T> for T
where T: Encode,

Source§

impl<T> EncodeLike<Arc<T>> for T
where T: Encode,

Source§

impl<T> EncodeLike<Box<T>> for T
where T: Encode,

Source§

impl<'a, T> EncodeLike<Cow<'a, T>> for T
where T: ToOwned + Encode,

Source§

impl<T> EncodeLike<Rc<T>> for T
where T: Encode,

Source§

impl<S> FullCodec for S
where S: Decode + FullEncode,

Source§

impl<S> FullEncode for S
where S: Encode + EncodeLike,

Source§

impl<T> JsonSchemaMaybe for T