pub struct HandleMap<T, U>{ /* private fields */ }
Expand description
An efficient implementation of a mapping between handles and arbitrary data.
This collection implements the classic “map” data-structure functionality, in the special case in which the keys are actually instances of Handle. This restriction enables this more efficient implementation of a map.
§Type Arguments
T
: The Handled type whose handles are used to index into the map.U
: The type of the target values being mapped.
§Example
struct LinkedListNode { next: Option<Handle<LinkedListNode>> }
impl Handled for LinkedListNode { type HandleCoreType = u8; }
let mut nodes = HandledVec::new();
let tail_handle = nodes.insert(LinkedListNode { next: None });
let head_handle = nodes.insert(LinkedListNode { next: Some(tail_handle) });
let mut metadata = HandleMap::new();
metadata.insert(head_handle, "Head Node");
metadata.insert(tail_handle, "Tail Node");
assert_eq!(metadata.get(tail_handle), Some("Tail Node").as_ref());
Implementations§
Source§impl<T, U> HandleMap<T, U>
impl<T, U> HandleMap<T, U>
Sourcepub fn get(&self, key: Handle<T>) -> Option<&U>
pub fn get(&self, key: Handle<T>) -> Option<&U>
Get a reference to the value mapped to a given key, or None if the key is not present.
Sourcepub fn get_mut(&mut self, key: Handle<T>) -> Option<&mut U>
pub fn get_mut(&mut self, key: Handle<T>) -> Option<&mut U>
Get a mutable reference to the value mapped to a given key, or None if the key was never inserted.
Sourcepub fn contains_key(&self, key: Handle<T>) -> bool
pub fn contains_key(&self, key: Handle<T>) -> bool
Check whether a given key is present in the map.
Trait Implementations§
Source§impl<'a, T, U> IntoIterator for &'a HandleMap<T, U>
impl<'a, T, U> IntoIterator for &'a HandleMap<T, U>
impl<T, U> Eq for HandleMap<T, U>
Auto Trait Implementations§
impl<T, U> Freeze for HandleMap<T, U>where
T: ?Sized,
impl<T, U> RefUnwindSafe for HandleMap<T, U>
impl<T, U> Send for HandleMap<T, U>
impl<T, U> Sync for HandleMap<T, U>
impl<T, U> Unpin for HandleMap<T, U>
impl<T, U> UnwindSafe for HandleMap<T, U>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more