Enum Entry

pub enum Entry<'a, T, A: Allocator + Clone = Global>

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

This enum is constructed from the entry method on BTreeSet.

Examples

#![feature(btree_set_entry)]

use std::collections::btree_set::BTreeSet;

let mut set = BTreeSet::new();
set.extend(["a", "b", "c"]);
assert_eq!(set.len(), 3);

// Existing value (insert)
let entry = set.entry("a");
let _raw_o = entry.insert();
assert_eq!(set.len(), 3);
// Nonexistent value (insert)
set.entry("d").insert();

// Existing value (or_insert)
set.entry("b").or_insert();
// Nonexistent value (or_insert)
set.entry("e").or_insert();

println!("Our BTreeSet: {:?}", set);
assert!(set.iter().eq(&["a", "b", "c", "d", "e"]));

Variants

Occupied(OccupiedEntry<'a, T, A>)

An occupied entry.

Examples

#![feature(btree_set_entry)]

use std::collections::btree_set::{Entry, BTreeSet};

let mut set = BTreeSet::from(["a", "b"]);

match set.entry("a") {
    Entry::Vacant(_) => unreachable!(),
    Entry::Occupied(_) => { }
}
Vacant(VacantEntry<'a, T, A>)

A vacant entry.

Examples

#![feature(btree_set_entry)]

use std::collections::btree_set::{Entry, BTreeSet};

let mut set = BTreeSet::new();

match set.entry("a") {
    Entry::Occupied(_) => unreachable!(),
    Entry::Vacant(_) => { }
}

Implementations

impl<'a, T: Ord, A: Allocator + Clone> Entry<'a, T, A>

fn insert(self) -> OccupiedEntry<'a, T, A>

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

Examples

#![feature(btree_set_entry)]

use std::collections::BTreeSet;

let mut set = BTreeSet::new();
let entry = set.entry("horseyland").insert();

assert_eq!(entry.get(), &"horseyland");
fn or_insert(self)

Ensures a value is in the entry by inserting if it was vacant.

Examples

#![feature(btree_set_entry)]

use std::collections::BTreeSet;

let mut set = BTreeSet::new();

// nonexistent key
set.entry("poneyland").or_insert();
assert!(set.contains("poneyland"));

// existing key
set.entry("poneyland").or_insert();
assert!(set.contains("poneyland"));
assert_eq!(set.len(), 1);
fn get(&self) -> &T

Returns a reference to this entry's value.

Examples

#![feature(btree_set_entry)]

use std::collections::BTreeSet;

let mut set = BTreeSet::new();
set.entry("poneyland").or_insert();

// existing key
assert_eq!(set.entry("poneyland").get(), &"poneyland");
// nonexistent key
assert_eq!(set.entry("horseland").get(), &"horseland");

Trait Implementations

impl<T: Debug + Ord, A: Allocator + Clone> Debug for Entry<'_, T, A>

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

Auto Trait Implementations

impl<'a, T, A = Global> !UnwindSafe for Entry<'a, T, A>

impl<'a, T, A> Freeze for Entry<'a, T, A> where OccupiedEntry<'a, T, A>: Freeze, VacantEntry<'a, T, A>: Freeze,

impl<'a, T, A> RefUnwindSafe for Entry<'a, T, A> where OccupiedEntry<'a, T, A>: RefUnwindSafe, VacantEntry<'a, T, A>: RefUnwindSafe,

impl<'a, T, A> Send for Entry<'a, T, A> where OccupiedEntry<'a, T, A>: Send, VacantEntry<'a, T, A>: Send,

impl<'a, T, A> Sync for Entry<'a, T, A> where OccupiedEntry<'a, T, A>: Sync, VacantEntry<'a, T, A>: Sync,

impl<'a, T, A> Unpin for Entry<'a, T, A> where OccupiedEntry<'a, T, A>: Unpin, VacantEntry<'a, T, A>: Unpin,

impl<'a, T, A> UnsafeUnpin for Entry<'a, T, A> where OccupiedEntry<'a, T, A>: UnsafeUnpin, VacantEntry<'a, T, A>: UnsafeUnpin,

Blanket Implementations

impl<T> Any for Entry<'a, T, A> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Entry<'a, T, A> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Entry<'a, T, A> where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for Entry<'a, T, A>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for Entry<'a, T, A> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for Entry<'a, T, A>

impl<T, U> Into<U> for Entry<'a, T, A> where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for Entry<'a, T, A> where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for Entry<'a, T, A> where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>