Enum Entry

Source
pub enum Entry<'v, T, K, V>
where T: Ord + Clone, K: Hash + Eq, V: OrdBy<Target = T>,
{ Occupied(RawEntry<'v, T, K, V>), Vacant(RawEntry<'v, T, K, V>), }
Expand description

Entry for an existing key-value pair in an ValordMap or a vacant location to insert one.

Variants§

§

Occupied(RawEntry<'v, T, K, V>)

Existing slot with equivalent key.

§

Vacant(RawEntry<'v, T, K, V>)

Vacant slot (no equivalent key in the map).

Implementations§

Source§

impl<'v, T, K, V> Entry<'v, T, K, V>
where T: Ord + Clone, K: Hash + Eq, V: OrdBy<Target = T>,

Source

pub fn or_insert(&mut self, default: V) -> &mut V

Inserts default value if the entry is vacant, and returns a mutable reference to the value.

§Examples
use valord_map::ValordMap;

let mut map = ValordMap::new();
map.entry("key").or_insert("value");

assert_eq!(map.get(&"key"), Some(&"value"));
Source

pub fn or_insert_with<F: FnOnce() -> V>(&mut self, default: F) -> &mut V

Inserts a value produced by the function default if the entry is vacant, and returns a mutable reference to the value.

§Examples
use valord_map::ValordMap;

let mut map = ValordMap::new();
map.entry("key").or_insert_with(|| "value");

assert_eq!(map.get(&"key"), Some(&"value"));
Source

pub fn or_insert_with_key<F: FnOnce(&K) -> V>(&mut self, default: F) -> &mut V

Inserts a value produced by the function default with the given key if the entry is vacant, and returns a mutable reference to the value.

§Examples
use valord_map::ValordMap;

let mut map = ValordMap::new();
map.entry("key").or_insert_with_key(|key| format!("value for {}", key));

assert_eq!(map.get(&"key"), Some(&"value for key".to_string()));
Source

pub fn and_modify<F>(self, f: F) -> Self
where F: FnOnce(&mut V),

Modifies the entry if it is occupied with the function f, and returns the entry.

§Examples
use valord_map::ValordMap;

let mut map = ValordMap::new();
map.entry("key").and_modify(|v| *v = "new value").or_insert("value");

assert_eq!(map.get(&"key"), Some(&"value"));

map.entry("key").and_modify(|v| *v = "new value").or_insert("value");

assert_eq!(map.get(&"key"), Some(&"new value"));
Source§

impl<'v, T, K, V> Entry<'v, T, K, V>
where T: Ord + Clone, K: Hash + Eq, V: OrdBy<Target = T> + Default,

Source

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

Inserts the default value if the entry is vacant, and returns a mutable reference to the value.

§Examples
use valord_map::ValordMap;

let mut map: ValordMap<usize, &str, usize> = ValordMap::new();
map.entry("key").or_default();

assert_eq!(map.get(&"key"), Some(&Default::default()));

Auto Trait Implementations§

§

impl<'v, T, K, V> Freeze for Entry<'v, T, K, V>

§

impl<'v, T, K, V> RefUnwindSafe for Entry<'v, T, K, V>

§

impl<'v, T, K, V> Send for Entry<'v, T, K, V>
where T: Send, K: Send, V: Send,

§

impl<'v, T, K, V> Sync for Entry<'v, T, K, V>
where T: Sync, K: Sync, V: Sync,

§

impl<'v, T, K, V> Unpin for Entry<'v, T, K, V>

§

impl<'v, T, K, V> !UnwindSafe for Entry<'v, T, 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.