[][src]Struct hashmap_entry_ownable::Entry

pub struct Entry<'a, 'q, K, Q: ?Sized, V, S> where
    K: Borrow<Q>,
    Q: ToOwned<Owned = K>, 
{ /* fields omitted */ }

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]

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]

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]

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]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.