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>
impl<'a, K: Hash + Eq, T> VacantEntry<'a, K, T>
Sourcepub fn insert_tail(self, value: T) -> (Ptr, &'a mut T)
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!(),
}Sourcepub fn insert_unlinked(self, value: T) -> (Ptr, &'a mut T)
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().
Sourcepub fn insert_after(self, value: T, after: Ptr) -> (Ptr, &'a mut T)
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 insertafter- 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)]);Sourcepub fn insert_head(self, value: T) -> (Ptr, &'a mut T)
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)]);Sourcepub fn insert_before(self, value: T, before: Ptr) -> (Ptr, &'a mut T)
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 insertbefore- 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)]);Sourcepub fn into_key(self) -> K
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);Sourcepub fn key(&self) -> &K
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!(),
}