Struct blaze_pk::types::TdfMap

source ·
pub struct TdfMap<K, V> { /* private fields */ }
Expand description

Structure for maps used in the protocol. These maps have a special order that is usually required and they retain the order of insertion because it uses two vecs as the underlying structure

Implementations§

source§

impl<K, V> TdfMap<K, V>

source

pub fn new() -> Self

Constructor implemention just uses the underlying default implemenation

source

pub fn with_capacity(capacity: usize) -> Self

Function for creating a new TdfMap where the underlying lists have an initial capacity

capacity The capacity

source

pub fn len(&self) -> usize

Returns the length of the underlying lists

source

pub fn is_empty(&self) -> bool

Returns if the underlying lists are empty

source

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

Creates a new iterator over the underlying items in the map

source

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

Returns the key and value stored at the provided index will return None if there is nothing at the provided index

source

pub fn insert<A: Into<K>, B: Into<V>>(&mut self, key: A, value: B)

Inserts a new key value pair into the underlying structure.

This function does NOT maintain order of the entires, use insert_ordered instead for maintaining the order

key The entry key value The entry value

source

pub fn pop(&mut self) -> Option<(K, V)>

Removes the last key and value returning them or None if there are no entries

source

pub fn clear(&mut self)

Removes all entries from the underlying list

source§

impl<K, V> TdfMap<K, V>where K: PartialOrd + Ord,

source

pub fn order(&mut self)

Orders this map based on its keys by ordering keys that are greater further up in the map

This function is quite slow compared to using insert_ordered for all the inserted entries. This is only for if you inserted with insert instead

source§

impl<K, V> TdfMap<K, V>where K: PartialEq + Eq,

source

pub fn extend(&mut self, other: TdfMap<K, V>)

Extends this map with the contents of another map. Any keys that already exist in the map will be replaced with the keys from the other map and any keys not present will be inserted

other The map to extend with

source

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

Removes a value by its key and returns the entry that was present at that position.

key The key to remove

source

pub fn get<Q>(&self, key: &Q) -> Option<&V>where K: Borrow<Q>, Q: Eq + ?Sized,

Returns the value stored at the provided key if its present or None.

key The key to retrieve the value for

source

pub fn get_mut<Q>(&mut self, key: &Q) -> Option<&mut V>where K: Borrow<Q>, Q: Eq + ?Sized,

Returns a mutable borrow to the value stored at the provided key if its present or None.

key The key to retrieve the value for

source

pub fn get_owned<Q>(&mut self, key: &Q) -> Option<V>where K: Borrow<Q>, Q: Eq + ?Sized,

Takes the value stored at the provided key out of the map taking ownership this also removes the key.

Trait Implementations§

source§

impl<K, V> Clone for TdfMap<K, V>where K: Clone, V: Clone,

source§

fn clone(&self) -> Self

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, V> Debug for TdfMap<K, V>where K: Debug, V: Debug,

source§

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

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

impl<K, V> Decodable for TdfMap<K, V>where K: Decodable + ValueType, V: Decodable + ValueType,

source§

fn decode(reader: &mut TdfReader<'_>) -> DecodeResult<Self>

Function for implementing decoding of Self from the provided Reader. Will return None if self cannot be decoded Read more
source§

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

source§

fn default() -> Self

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

impl<K, V> Encodable for TdfMap<K, V>where K: Encodable + ValueType, V: Encodable + ValueType,

source§

fn encode(&self, output: &mut TdfWriter)

Function for implementing encoding of Self to the provided vec of bytes Read more
source§

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

Shortcut function for encoding self directly to a Vec of bytes
source§

impl<K, V> From<HashMap<K, V, RandomState>> for TdfMap<K, V>

Implementation for converting a HashMap to a TdfMap by taking all its keys and values and building lists for the TdfMap

source§

fn from(map: HashMap<K, V>) -> Self

Converts to this type from the input type.
source§

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

Into iterator implementation for borrowed map

§

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

The type of the elements being iterated over.
§

type IntoIter = MapEntryIter<'a, 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, V> IntoIterator for TdfMap<K, V>

Into iterator implementation for owned map

§

type Item = (K, V)

The type of the elements being iterated over.
§

type IntoIter = OwnedMapEntryIter<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, V> Serialize for TdfMap<K, V>where K: Serialize, V: Serialize,

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<K, V> ValueType for TdfMap<K, V>

source§

fn value_type() -> TdfType

The type of tdf value this is

Auto Trait Implementations§

§

impl<K, V> RefUnwindSafe for TdfMap<K, V>where K: RefUnwindSafe, V: RefUnwindSafe,

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<D> FromRequest for Dwhere D: Decodable + Send + 'static,

source§

fn from_request(req: &Packet) -> Result<D, DecodeError>

Takes the value from the request returning a decode result of whether the value could be created Read more
source§

impl<F> FromRequestInternal for Fwhere F: FromRequest,

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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<E> IntoResponse for Ewhere E: Encodable + 'static,

source§

fn into_response(self, req: &Packet) -> Packet

Into packet conversion
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more