Struct HandleMap

Source
pub struct HandleMap<T, U>
where T: Handled + ?Sized,
{ /* 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>
where T: Handled + ?Sized,

Source

pub fn new() -> Self

Create a new, empty, map.

Source

pub fn insert(&mut self, key: Handle<T>, item: U) -> bool

Insert a key-value pair to the map.

Source

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.

Source

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.

Source

pub fn contains_key(&self, key: Handle<T>) -> bool

Check whether a given key is present in the map.

Source

pub fn iter(&self) -> impl Iterator<Item = (Handle<T>, &U)>

Get an iterator of references to the values held in the maps, and their corresponding keys.

Source

pub fn keys<'a>(&'a self) -> impl Iterator<Item = Handle<T>> + 'a

Get an iterator over the available keys in the map.

Trait Implementations§

Source§

impl<T, U> Clone for HandleMap<T, U>
where T: Handled + ?Sized, U: Clone,

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, U> Debug for HandleMap<T, U>
where T: Handled, U: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T, U> From<Vec<Option<U>>> for HandleMap<T, U>
where T: Handled + ?Sized,

Source§

fn from(contents: Vec<Option<U>>) -> Self

Converts to this type from the input type.
Source§

impl<'a, T, U> IntoIterator for &'a HandleMap<T, U>
where T: Handled + ?Sized,

Source§

type Item = (Handle<T>, &'a U)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T, U>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<T, U> PartialEq for HandleMap<T, U>
where T: Handled + ?Sized, U: PartialEq,

Source§

fn eq(&self, __other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T, U> Eq for HandleMap<T, U>
where T: Handled + ?Sized, U: Eq,

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>
where <T as Handled>::HandleCoreType: Send, U: Send, T: ?Sized,

§

impl<T, U> Sync for HandleMap<T, U>
where <T as Handled>::HandleCoreType: Sync, U: Sync, T: ?Sized,

§

impl<T, U> Unpin for HandleMap<T, U>
where <T as Handled>::HandleCoreType: Unpin, U: Unpin, T: ?Sized,

§

impl<T, U> UnwindSafe for HandleMap<T, U>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.