[−][src]Struct hashmap_entry_ownable::Entry
Methods
impl<'a, 'q, K, Q: ?Sized, V, S> Entry<'a, 'q, K, Q, V, S> where
K: Borrow<Q> + Hash,
Q: ToOwned<Owned = K>,
S: BuildHasher,
[src]
K: Borrow<Q> + Hash,
Q: ToOwned<Owned = K>,
S: BuildHasher,
pub fn or_insert(self, default: V) -> &'a mut V
[src]
Ensures a value is in the entry by inserting the default if empty, and returns a mutable reference to the value in the entry.
Examples
use std::collections::HashMap; use hashmap_entry_ownable::EntryAPI; let mut map: HashMap<String, u32> = HashMap::new(); map.entry_ownable("poneyland").or_insert(3); assert_eq!(map["poneyland"], 3); *map.entry_ownable("poneyland").or_insert(10) *= 2; assert_eq!(map["poneyland"], 6);
pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V
[src]
Ensures a value is in the entry by inserting the result of the default function if empty, and returns a mutable reference to the value in the entry.
Examples
use std::collections::HashMap; use hashmap_entry_ownable::EntryAPI; let mut map: HashMap<String, String> = HashMap::new(); let s = "hoho".to_string(); map.entry_ownable("poneyland").or_insert_with(|| s); assert_eq!(map["poneyland"], "hoho".to_string());
pub fn and_modify<F>(self, f: F) -> Self where
F: FnOnce(&mut V),
[src]
F: FnOnce(&mut V),
Provides in-place mutable access to an occupied entry before any potential inserts into the map.
Examples
use std::collections::HashMap; use hashmap_entry_ownable::EntryAPI; let mut map: HashMap<String, u32> = HashMap::new(); map.entry_ownable("poneyland") .and_modify(|e| { *e += 1 }) .or_insert(42); assert_eq!(map["poneyland"], 42); map.entry_ownable("poneyland") .and_modify(|e| { *e += 1 }) .or_insert(42); assert_eq!(map["poneyland"], 43);
impl<'a, 'q, K, Q: ?Sized, V, S> Entry<'a, 'q, K, Q, V, S> where
K: Borrow<Q> + Hash,
Q: ToOwned<Owned = K>,
V: Default,
S: BuildHasher,
[src]
K: Borrow<Q> + Hash,
Q: ToOwned<Owned = K>,
V: Default,
S: BuildHasher,
pub fn or_default(self) -> &'a mut V
[src]
Ensures a value is in the entry by inserting the default value if empty, and returns a mutable reference to the value in the entry.
Examples
use std::collections::HashMap; use hashmap_entry_ownable::EntryAPI; let mut map: HashMap<String, Option<u32>> = HashMap::new(); map.entry_ownable("poneyland").or_default(); assert_eq!(map["poneyland"], None);
Auto Trait Implementations
impl<'a, 'q, K, Q, V, S> !Send for Entry<'a, 'q, K, Q, V, S>
impl<'a, 'q, K, Q, V, S> !Sync for Entry<'a, 'q, K, Q, V, S>
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,