VacantEntry

Struct VacantEntry 

Source
pub struct VacantEntry<'a, K, T> { /* private fields */ }
Expand description

A view into a vacant entry in a LinkedHashMap.

It is part of the Entry enum.

§Examples

use tether_map::Entry;
use tether_map::LinkedHashMap;

let mut map = LinkedHashMap::new();

if let Entry::Vacant(entry) = map.entry("key") {
    entry.insert_tail("value");
}
assert_eq!(map.get(&"key"), Some(&"value"));

Implementations§

Source§

impl<'a, K: Hash + Eq, T> VacantEntry<'a, K, T>

Source

pub fn insert_tail(self, value: T) -> (Ptr, &'a mut T)

Inserts a new entry at the tail (end) of the linked list.

§Arguments
  • value - The value to insert
§Returns

The pointer to the newly inserted entry

§Examples
use tether_map::Entry;
use tether_map::LinkedHashMap;

let mut map = LinkedHashMap::new();

match map.entry("new_key") {
    Entry::Vacant(entry) => {
        let value = entry.insert_tail(42).1;
        assert_eq!(*value, 42);
    }
    Entry::Occupied(_) => unreachable!(),
}
Source

pub fn insert_unlinked(self, value: T) -> (Ptr, &'a mut T)

Inserts a new entry without linking it to the doubly-linked list.

This is a low-level method that creates an entry in the hash table but does not link it into the ordered list. The entry will exist in the map but won’t appear in iteration order until it’s properly linked. It can still be accessed either by the returned pointer or by its key.

§Arguments
  • value - The value to insert
§Returns

The pointer to the newly created but unlinked entry

§Note

This method is primarily for advanced usage. Most users should use insert_tail(), insert_head(), or similar methods instead. This is most useful when you have an entry and want to store data in the map, but also need to operate on the linked list structure separately without including the new entry in the list yet. In that case, you can create the entry with push_unlinked() and then later link it in using methods like link_as_head(), or link_as_tail().

Source

pub fn insert_after(self, value: T, after: Ptr) -> (Ptr, &'a mut T)

Inserts a new entry immediately after the specified entry.

§Arguments
  • value - The value to insert
  • after - The pointer to the entry after which to insert
§Returns

The pointer to the newly inserted entry

§Examples
use tether_map::Entry;
use tether_map::LinkedHashMap;

let mut map = LinkedHashMap::new();
let (ptr1, _) = map.insert_tail_full("first", 1);
map.insert_tail("third", 3);

match map.entry("second") {
    Entry::Vacant(entry) => {
        entry.insert_after(2, ptr1);
    }
    Entry::Occupied(_) => unreachable!(),
}

// Order is now: first, second, third
let entries: Vec<_> = map.iter().collect();
assert_eq!(entries, [(&"first", &1), (&"second", &2), (&"third", &3)]);
Source

pub fn insert_head(self, value: T) -> (Ptr, &'a mut T)

Inserts a new entry at the head (beginning) of the linked list.

§Arguments
  • value - The value to insert
§Returns

The pointer to the newly inserted entry

§Examples
use tether_map::Entry;
use tether_map::LinkedHashMap;

let mut map = LinkedHashMap::new();
map.insert_tail("second", 2);

match map.entry("first") {
    Entry::Vacant(entry) => {
        let ptr = entry.insert_head(1).0;
        assert_eq!(map.ptr_get(ptr), Some(&1));
    }
    Entry::Occupied(_) => unreachable!(),
}

// Order is now: first, second
let entries: Vec<_> = map.iter().collect();
assert_eq!(entries, [(&"first", &1), (&"second", &2)]);
Source

pub fn insert_before(self, value: T, before: Ptr) -> (Ptr, &'a mut T)

Inserts a new entry immediately before the specified entry.

§Arguments
  • value - The value to insert
  • before - The pointer to the entry before which to insert
§Returns

The pointer to the newly inserted entry

§Examples
use tether_map::Entry;
use tether_map::LinkedHashMap;

let mut map = LinkedHashMap::new();
map.insert_tail("first", 1);
let (ptr3, _) = map.insert_tail_full("third", 3);

match map.entry("second") {
    Entry::Vacant(entry) => {
        entry.insert_before(2, ptr3);
    }
    Entry::Occupied(_) => unreachable!(),
}

// Order is now: first, second, third
let entries: Vec<_> = map.iter().collect();
assert_eq!(entries, [(&"first", &1), (&"second", &2), (&"third", &3)]);
Source

pub fn into_key(self) -> K

Consumes this vacant entry and returns the key.

This method allows you to retrieve the key without inserting a value, which can be useful when the insertion is conditional.

§Returns

The key that would have been inserted

§Examples
use tether_map::Entry;
use tether_map::LinkedHashMap;

let mut map: LinkedHashMap<&str, i32> = LinkedHashMap::new();

match map.entry("key") {
    Entry::Vacant(entry) => {
        let key = entry.into_key();
        assert_eq!(key, "key");
        // Entry was not inserted
    }
    Entry::Occupied(_) => unreachable!(),
}
assert_eq!(map.len(), 0);
Source

pub fn key(&self) -> &K

Returns a reference to the key that would be inserted.

§Examples
use tether_map::Entry;
use tether_map::LinkedHashMap;

let mut map = LinkedHashMap::new();

match map.entry("key") {
    Entry::Vacant(entry) => {
        assert_eq!(entry.key(), &"key");
        entry.insert_tail(42);
    }
    Entry::Occupied(_) => unreachable!(),
}

Auto Trait Implementations§

§

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

§

impl<'a, K, T> !RefUnwindSafe for VacantEntry<'a, K, T>

§

impl<'a, K, T> !Send for VacantEntry<'a, K, T>

§

impl<'a, K, T> !Sync for VacantEntry<'a, K, T>

§

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

§

impl<'a, K, T> !UnwindSafe for VacantEntry<'a, K, T>

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.