Skip to main content

DictMap

Struct DictMap 

Source
pub struct DictMap<K: Eq + Hash, V> { /* private fields */ }
Expand description

Generic typed map keyed by K with an ahash hasher.

The wrapper exposes the small set of operations used by the rest of the engine and intentionally hides the underlying hasher and table layout. Use DictMap::iter for read-only traversal and DictMap::drain when you need to consume the entire map.

§Examples

use dynomite::util::dict::DictMap;

let mut m: DictMap<&'static str, u32> = DictMap::new();
m.insert("k", 7);
assert_eq!(m.get(&"k"), Some(&7));
assert_eq!(m.len(), 1);
assert!(m.remove(&"k").is_some());
assert!(m.is_empty());

Implementations§

Source§

impl<K: Eq + Hash, V> DictMap<K, V>

Source

pub fn new() -> Self

Construct an empty map.

§Examples
use dynomite::util::dict::DictMap;
let m: DictMap<u32, u32> = DictMap::new();
assert!(m.is_empty());
Source

pub fn with_capacity(capacity: usize) -> Self

Construct an empty map with at least capacity slots.

§Examples
use dynomite::util::dict::DictMap;
let m: DictMap<u32, u32> = DictMap::with_capacity(8);
assert!(m.is_empty());
Source

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

Insert value at key, returning the previous value (if any).

§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
assert_eq!(m.insert(1, 10), None);
assert_eq!(m.insert(1, 20), Some(10));
Source

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

Remove and return the value at key.

§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
assert_eq!(m.remove(&1), Some(10));
assert_eq!(m.remove(&1), None);
Source

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

Look up an immutable reference to the value at key.

§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
assert_eq!(m.get(&1), Some(&10));
Source

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

Look up a mutable reference to the value at key.

§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
*m.get_mut(&1).unwrap() = 20;
assert_eq!(m.get(&1), Some(&20));
Source

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

Whether key is in the map.

§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
assert!(m.contains_key(&1));
assert!(!m.contains_key(&2));
Source

pub fn len(&self) -> usize

Number of entries.

§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
assert_eq!(m.len(), 1);
Source

pub fn is_empty(&self) -> bool

Whether the map is empty.

§Examples
use dynomite::util::dict::DictMap;
let m: DictMap<u32, u32> = DictMap::new();
assert!(m.is_empty());
Source

pub fn clear(&mut self)

Drop every entry.

§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
m.clear();
assert!(m.is_empty());
Source

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

Borrowed iterator over (key, value) pairs.

§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
m.insert(2, 20);
let mut sum = 0u32;
for (_k, v) in m.iter() { sum += v; }
assert_eq!(sum, 30);
Source

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

Mutable iterator over (key, value) pairs.

§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
for (_k, v) in m.iter_mut() { *v += 1; }
assert_eq!(m.get(&1), Some(&11));
Source

pub fn drain(&mut self) -> impl Iterator<Item = (K, V)> + '_

Consume the map and yield (key, value) pairs.

§Examples
use dynomite::util::dict::DictMap;
let mut m: DictMap<u32, u32> = DictMap::new();
m.insert(1, 10);
let drained: Vec<_> = m.drain().collect();
assert_eq!(drained, vec![(1, 10)]);
assert!(m.is_empty());

Trait Implementations§

Source§

impl<K: Clone + Eq + Hash, V: Clone> Clone for DictMap<K, V>

Source§

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

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<K: Debug + Eq + Hash, V: Debug> Debug for DictMap<K, V>

Source§

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

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

impl<K: Default + Eq + Hash, V: Default> Default for DictMap<K, V>

Source§

fn default() -> DictMap<K, V>

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

impl<K: Eq + Hash, V> IntoIterator for DictMap<K, V>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<K, V> UnsafeUnpin for DictMap<K, V>

§

impl<K, V> UnwindSafe for DictMap<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> 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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 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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,