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

A newtype wrapping a HashMap which allows a default value to be defined. When a key is not found in the HashMap the default value is returned, instead of None.

Implementations§

source§

impl<K, V> HashMapWithDefault<K, V>

source

pub fn new(default: V) -> Self

Create a new hash map with the given default value.

source

pub fn get_ref(&self) -> &HashMap<K, V>

Get a reference to the inner HashMap.

source

pub fn get_mut(&mut self) -> &mut HashMap<K, V>

Get a mutable reference to the inner HashMap.

source

pub fn default(&self) -> &V

Returns a reference to the default value.

source

pub fn mut_default(&mut self) -> &mut V

Returns a mutable reference to the default value.

source§

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

source

pub fn get<Q: ?Sized + Hash + Eq>(&self, index: &Q) -> &Vwhere K: Borrow<Q>,

Lookup up the item with the given key in the hash table. If no value is found then the default is returned.

Trait Implementations§

source§

impl<Q: ?Sized + Hash + Eq, K: Borrow<Q> + Hash + Eq, V> Index<&Q> for HashMapWithDefault<K, V>

§

type Output = V

The returned type after indexing.
source§

fn index(&self, index: &Q) -> &Self::Output

Performs the indexing (container[index]) operation. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<K, V> UnwindSafe for HashMapWithDefault<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
§

impl<T> Free for T

§

unsafe default fn free(ptr_ref: NonNull<T>)

Drops the content pointed by this pointer and frees it. 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 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<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.