[][src]Enum weighted_random_list::Entry

pub enum Entry<'container, T> {
    Vacant {
        arena: &'container mut WeightedRandomList<T>,
        needle: T,
    },
    Occupied {
        arena: &'container mut WeightedRandomList<T>,
        index: usize,
    },
}

Update or insert one entry inside the the list.

Variants

Vacant

Fields of Vacant

arena: &'container mut WeightedRandomList<T>needle: T
Occupied

Fields of Occupied

arena: &'container mut WeightedRandomList<T>index: usize

Methods

impl<'container, T> Entry<'container, T>[src]

pub fn set_weight(&mut self, new_weight: usize)[src]

Panics if Entry is Vacant

let mut l = WeightedRandomList::new();

l.push(12, 42);
let mut element = l.entry_first(&42).or_insert_with_weight(10);

element.set_weight(100);

pub fn or_insert_with_weight(self, weight: usize) -> Self[src]

Inserts if Entry is Vacant. Does nothing if found inside the list.

let mut l = WeightedRandomList::new();

// add 42 with weight 10
l.entry_first(&42).or_insert_with_weight(10);

pub fn delete(self) -> Result<(), ()>[src]

Remove Entry if it exists.

Errors if it does not exist.

let mut l = WeightedRandomList::new();
l.push(12, 11);
l.push(74, 22);
l.push(25, 33);

{
    let second = l.entry_first(&22);
    assert!(second.delete().is_ok(), "element was found and deleted");
}

{
    let second = l.entry_first(&22);
    assert!(second.delete().is_err(), "element alread gone");
}

Auto Trait Implementations

impl<'container, T> Send for Entry<'container, T> where
    T: Send

impl<'container, T> Sync for Entry<'container, T> where
    T: Sync

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<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.