Map

Struct Map 

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

A concurrent map, Map is like sync.Map in Golang.

  • K must implement Eq + PartialEq + Hash.
  • V must implement Eq + PartialEq + Clone.

Implementations§

Source§

impl<K, V> Map<K, V>
where K: Eq + PartialEq + Hash, V: Eq + PartialEq + Clone,

Source

pub fn new() -> Self

Create a new Map.

Source

pub fn compare_and_delete(&self, k: K, v: V) -> bool

compare_and_delete deletes the key-value pair for the given key if the value is equal to the given value. returns true if the kv was already in. returns false if the kv was not in.

Source

pub fn compare_and_swap(&self, k: K, old_v: V, new_v: V) -> bool

compare_and_swap sets the value for the given key if the value is equal to the given old value. returns true if the kv was already in. returns false if the kv was not in.

Source

pub fn store(&self, k: K, v: V)

store sets the value for the given key.

Source

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

load returns the value stored in the map for a key, or none if no value is present.

Source

pub fn get<F>(&self, k: K, f: F) -> bool
where F: FnMut(&V),

without clone: a little faster return true if the key is in the map, false otherwise.

Source

pub fn delete(&self, k: K)

delete deletes the key-value pair for the given key.

Source

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

load_and_delete deletes the key-value pair for the given key and returns the value

Source

pub fn load_or_store(&self, k: K, v: V) -> V

load_or_store returns the existing value for the key if present. otherwise, it stores and returns the given value.

Source

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

swap swaps the value for a key and returns the old value

Source

pub fn range<F>(&self, f: F)
where F: FnMut(&K, &V) -> bool,

range calls f sequentially for each key and value present in the map. if f returns false, range stops the iteration.

Trait Implementations§

Source§

impl<K, V> Default for Map<K, V>
where K: Eq + PartialEq + Hash, V: Eq + PartialEq + Clone,

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

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

§

impl<K, V> !RefUnwindSafe for Map<K, V>

§

impl<K, V> Send for Map<K, V>
where K: Send + Sync, V: Send + Sync,

§

impl<K, V> Sync for Map<K, V>
where K: Send + Sync, V: Send + Sync,

§

impl<K, V> Unpin for Map<K, V>

§

impl<K, V> !UnwindSafe for Map<K, V>

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> 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, 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.