Entry

Enum Entry 

Source
pub enum Entry<'a, T, V, Ix> {
    Occupied(OccupiedEntry<'a, T, V, Ix>),
    Vacant(VacantEntry<'a, T, V, Ix>),
}
Expand description

A view into a single entry in a map, which may either be vacant or occupied.

Variants§

§

Occupied(OccupiedEntry<'a, T, V, Ix>)

An occupied entry.

§

Vacant(VacantEntry<'a, T, V, Ix>)

A vacant entry.

Implementations§

Source§

impl<'a, T, V, Ix> Entry<'a, T, V, Ix>
where T: Ord, Ix: IndexType,

Source

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

Ensures a value is in the entry by inserting the default if empty, and returns a mutable reference to the value in the entry.

§Example
use rb_interval_map::{Interval, IntervalMap, Entry};

let mut map = IntervalMap::new();
assert!(matches!(map.entry(Interval::new(1, 2)), Entry::Vacant(_)));
map.entry(Interval::new(1, 2)).or_insert(3);
assert!(matches!(map.entry(Interval::new(1, 2)), Entry::Occupied(_)));
assert_eq!(map.get(&Interval::new(1, 2)), Some(&3));
Source

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

Provides in-place mutable access to an occupied entry before any potential inserts into the map.

§Panics

This method panics when the node is a sentinel node

§Example
use rb_interval_map::{Interval, IntervalMap, Entry};

let mut map = IntervalMap::new();

map.insert(Interval::new(6, 7), 3);
assert!(matches!(map.entry(Interval::new(6, 7)), Entry::Occupied(_)));
map.entry(Interval::new(6, 7)).and_modify(|v| *v += 1);
assert_eq!(map.get(&Interval::new(6, 7)), Some(&4));

Trait Implementations§

Source§

impl<'a, T: Debug, V: Debug, Ix: Debug> Debug for Entry<'a, T, V, Ix>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, T, V, Ix> Freeze for Entry<'a, T, V, Ix>
where Ix: Freeze, T: Freeze,

§

impl<'a, T, V, Ix> RefUnwindSafe for Entry<'a, T, V, Ix>

§

impl<'a, T, V, Ix> Send for Entry<'a, T, V, Ix>
where Ix: Send, T: Send, V: Send,

§

impl<'a, T, V, Ix> Sync for Entry<'a, T, V, Ix>
where Ix: Sync, T: Sync, V: Sync,

§

impl<'a, T, V, Ix> Unpin for Entry<'a, T, V, Ix>
where Ix: Unpin, T: Unpin,

§

impl<'a, T, V, Ix> !UnwindSafe for Entry<'a, T, V, Ix>

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.