std::collections::btree_set

Struct VacantEntry

Source
pub struct VacantEntry<'a, T, A = Global>
where A: Allocator + Clone,
{ /* private fields */ }
🔬This is a nightly-only experimental API. (btree_set_entry #133549)
Expand description

A view into a vacant entry in a BTreeSet. It is part of the Entry enum.

§Examples

#![feature(btree_set_entry)]

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

let mut set = BTreeSet::<&str>::new();

let entry_v = match set.entry("a") {
    Entry::Vacant(view) => view,
    Entry::Occupied(_) => unreachable!(),
};
entry_v.insert();
assert!(set.contains("a") && set.len() == 1);

// Nonexistent key (insert)
match set.entry("b") {
    Entry::Vacant(view) => view.insert(),
    Entry::Occupied(_) => unreachable!(),
}
assert!(set.contains("b") && set.len() == 2);

Implementations§

Source§

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

Source

pub fn get(&self) -> &T

🔬This is a nightly-only experimental API. (btree_set_entry #133549)

Gets a reference to the value that would be used when inserting through the VacantEntry.

§Examples
#![feature(btree_set_entry)]

use std::collections::BTreeSet;

let mut set = BTreeSet::new();
assert_eq!(set.entry("poneyland").get(), &"poneyland");
Source

pub fn into_value(self) -> T

🔬This is a nightly-only experimental API. (btree_set_entry #133549)

Take ownership of the value.

§Examples
#![feature(btree_set_entry)]

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

let mut set = BTreeSet::new();

match set.entry("poneyland") {
    Entry::Occupied(_) => panic!(),
    Entry::Vacant(v) => assert_eq!(v.into_value(), "poneyland"),
}
Source

pub fn insert(self)

🔬This is a nightly-only experimental API. (btree_set_entry #133549)

Sets the value of the entry with the VacantEntry’s value.

§Examples
#![feature(btree_set_entry)]

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

let mut set = BTreeSet::new();

if let Entry::Vacant(o) = set.entry("poneyland") {
    o.insert();
}
assert!(set.contains("poneyland"));

Trait Implementations§

Source§

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

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

impl<'a, T, A> RefUnwindSafe for VacantEntry<'a, T, A>

§

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

§

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

§

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

§

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

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.