[][src]Struct slotmap::secondary::OccupiedEntry

pub struct OccupiedEntry<'a, K: Key, V> { /* fields omitted */ }

A view into a occupied entry in a SecondaryMap. It is part of the Entry enum.

Implementations

impl<'a, K: Key, V> OccupiedEntry<'a, K, V>[src]

pub fn key(&self) -> K[src]

Returns this entry's key.

Examples

let mut sm = SlotMap::new();
let mut sec = SecondaryMap::new();

let k = sm.insert(1);
sec.insert(k, 10);
assert_eq!(sec.entry(k).unwrap().key(), k);

pub fn remove_entry(self) -> (K, V)[src]

Removes the entry from the slot map and returns the key and value.

Examples

let mut sm = SlotMap::new();
let mut sec = SecondaryMap::new();

let foo = sm.insert("foo");
sec.entry(foo).unwrap().or_insert("bar");

if let Some(Entry::Occupied(o)) = sec.entry(foo) {
    assert_eq!(o.remove_entry(), (foo, "bar"));
}
assert_eq!(sec.contains_key(foo), false);

pub fn get(&self) -> &V[src]

Gets a reference to the value in the entry.

Examples

let mut sm = SlotMap::new();
let mut sec = SecondaryMap::new();

let k = sm.insert(1);
sec.insert(k, 10);

if let Entry::Occupied(o) = sec.entry(k).unwrap() {
    assert_eq!(*o.get(), 10);
}

pub fn get_mut(&mut self) -> &mut V[src]

Gets a mutable reference to the value in the entry.

If you need a reference to the OccupiedEntry which may outlive the destruction of the Entry value, see into_mut.

Examples

let mut sm = SlotMap::new();
let mut sec = SecondaryMap::new();

let k = sm.insert(1);
sec.insert(k, 10);
if let Entry::Occupied(mut o) = sec.entry(k).unwrap() {
    *o.get_mut() = 20;
}
assert_eq!(sec[k], 20);

pub fn into_mut(self) -> &'a mut V[src]

Converts the OccupiedEntry into a mutable reference to the value in the entry with a lifetime bound to the map itself.

If you need multiple references to the OccupiedEntry, see get_mut.

Examples

let mut sm = SlotMap::new();
let mut sec = SecondaryMap::new();

let k = sm.insert(0);
sec.insert(k, 0);

let r;
if let Entry::Occupied(o) = sec.entry(k).unwrap() {
    r = o.into_mut(); // v outlives the entry.
} else {
    r = sm.get_mut(k).unwrap();
}
*r = 1;
assert_eq!((sm[k], sec[k]), (0, 1));

pub fn insert(&mut self, value: V) -> V[src]

Sets the value of the entry, and returns the entry's old value.

Examples

let mut sm = SlotMap::new();
let mut sec = SecondaryMap::new();

let k = sm.insert(1);
sec.insert(k, 10);

if let Entry::Occupied(mut o) = sec.entry(k).unwrap() {
    let v = o.insert(20);
    assert_eq!(v, 10);
    assert_eq!(*o.get(), 20);
}

pub fn remove(self) -> V[src]

Takes the value out of the entry, and returns it.

Examples


let mut sm = SlotMap::new();
let mut sec = SecondaryMap::new();

let k = sm.insert(1);
sec.insert(k, 10);

if let Entry::Occupied(mut o) = sec.entry(k).unwrap() {
    assert_eq!(o.remove(), 10);
    assert_eq!(sec.contains_key(k), false);
}

Trait Implementations

impl<'a, K: Debug + Key, V: Debug> Debug for OccupiedEntry<'a, K, V>[src]

Auto Trait Implementations

impl<'a, K, V> RefUnwindSafe for OccupiedEntry<'a, K, V> where
    V: RefUnwindSafe
[src]

impl<'a, K, V> Send for OccupiedEntry<'a, K, V> where
    V: Send
[src]

impl<'a, K, V> Sync for OccupiedEntry<'a, K, V> where
    V: Sync
[src]

impl<'a, K, V> Unpin for OccupiedEntry<'a, K, V>[src]

impl<'a, K, V> !UnwindSafe for OccupiedEntry<'a, K, V>[src]

Blanket Implementations

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

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

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

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

The type returned in the event of a conversion error.