pub enum Entry<'a, R, V>{
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§
Implementations§
Source§impl<'a, R, V> Entry<'a, R, V>
impl<'a, R, V> Entry<'a, R, V>
Sourcepub fn key(&self) -> &Range<R>
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));Sourcepub fn or_insert(self, default: V) -> &'a mut V
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));Sourcepub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V
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()));Sourcepub fn or_insert_with_key<F: FnOnce(&Range<R>) -> V>(
self,
default: F,
) -> &'a mut V
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));Sourcepub fn and_modify<F: FnOnce(&mut V)>(self, f: F) -> Self
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));Sourcepub fn insert_entry(self, value: V) -> OccupiedEntry<'a, R, V>
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>
impl<'a, R, V> Entry<'a, R, V>
Sourcepub fn or_default(self) -> &'a mut V
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));