Entry

Enum Entry 

Source
pub enum Entry<'a, R, V>
where R: Ord + Clone + Debug,
{ Vacant(VacantEntry<'a, R, V>), Occupied(OccupiedEntry<'a, R, V>), }
Expand description

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

This enum is constructed from the entry method on IntervalTree.

Variants§

§

Vacant(VacantEntry<'a, R, V>)

A vacant entry.

§

Occupied(OccupiedEntry<'a, R, V>)

An occupied entry.

Implementations§

Source§

impl<'a, R, V> Entry<'a, R, V>
where R: Ord + Clone + Debug,

Source

pub fn key(&self) -> &Range<R>

Returns a reference to this entry’s key.

§Examples
use interavl::IntervalTree;

let mut tree: IntervalTree<i32, &str> = IntervalTree::default();
assert_eq!(tree.entry(0..10).key(), &(0..10));
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.

§Examples
use interavl::IntervalTree;

let mut tree: IntervalTree<i32, u32> = IntervalTree::default();

tree.entry(0..10).or_insert(42);
assert_eq!(tree.get(&(0..10)), Some(&42));

*tree.entry(0..10).or_insert(100) += 1;
assert_eq!(tree.get(&(0..10)), Some(&43));
Source

pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V

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 interavl::IntervalTree;

let mut tree: IntervalTree<i32, String> = IntervalTree::default();
let s = "hello".to_string();

tree.entry(0..10).or_insert_with(|| s);

assert_eq!(tree.get(&(0..10)), Some(&"hello".to_string()));
Source

pub fn or_insert_with_key<F: FnOnce(&Range<R>) -> V>( self, default: F, ) -> &'a mut V

Ensures a value is in the entry by inserting, if empty, the result of the default function. This method allows for generating key-derived values for insertion by providing the default function a reference to the key that was moved during the .entry(key) method call.

§Examples
use interavl::IntervalTree;

let mut tree: IntervalTree<i32, i32> = IntervalTree::default();

tree.entry(0..10).or_insert_with_key(|key| key.start + key.end);

assert_eq!(tree.get(&(0..10)), Some(&10));
Source

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

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

§Examples
use interavl::IntervalTree;

let mut tree: IntervalTree<i32, u32> = IntervalTree::default();

tree.entry(0..10)
    .and_modify(|v| *v += 1)
    .or_insert(42);
assert_eq!(tree.get(&(0..10)), Some(&42));

tree.entry(0..10)
    .and_modify(|v| *v += 1)
    .or_insert(42);
assert_eq!(tree.get(&(0..10)), Some(&43));
Source

pub fn insert_entry(self, value: V) -> OccupiedEntry<'a, R, V>

Sets the value of the entry, and returns an OccupiedEntry.

§Examples
use interavl::IntervalTree;

let mut tree: IntervalTree<i32, &str> = IntervalTree::default();
let entry = tree.entry(0..10).insert_entry("hello");

assert_eq!(entry.key(), &(0..10));
Source§

impl<'a, R, V> Entry<'a, R, V>
where R: Ord + Clone + Debug, V: Default,

Source

pub fn or_default(self) -> &'a mut V

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 interavl::IntervalTree;

let mut tree: IntervalTree<i32, Option<u32>> = IntervalTree::default();
tree.entry(0..10).or_default();

assert_eq!(tree.get(&(0..10)), Some(&None));

Trait Implementations§

Source§

impl<'a, R, V: Debug> Debug for Entry<'a, R, V>
where R: Ord + Clone + Debug + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

impl<'a, R, V> RefUnwindSafe for Entry<'a, R, V>

§

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

§

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

§

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

§

impl<'a, R, V> !UnwindSafe for Entry<'a, R, V>

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.