Struct HandledHashMap

Source
pub struct HandledHashMap<T>
where T: Handled + Eq + PartialEq + Hash,
{ /* private fields */ }
Expand description

A collection of Handled instances with automatically-generated handles, supporting efficient hash-based instance-to-handle lookup.

This data structure accumulates instances of some Handled type T, while automatically generating handles to each of the contained instances, based on their order of insertion to the vector. It supports efficient hash-based instance-to-handle lookup.

This usually serves for generating handles to instances of simple data types, not simple enough to be AutomaticallyHandled.

§Example

struct Animal(String);
impl Handled for Animal {
    type HandleCoreType = u8;
}
let mut animals = HandledHashMap::new();
let dog_handle = animals.insert(Animal(String::from("dog")));
let cat_handle = animals.insert(Animal(String::from("cat")));

Implementations§

Source§

impl<T> HandledHashMap<T>
where T: Handled + Eq + PartialEq + Hash,

Source

pub fn new() -> Self

Create a new, empty, collection.

Source

pub fn contains(&self, item: &T) -> bool

Check whether the collection contains a given item.

Source

pub fn insert(&mut self, item: T)

Insert a new item into the collection (if it is not already there).

Source

pub fn get_handle(&self, item: &T) -> Option<&Handle<T>>

Get the handle associated with one of the collection’s items, or None if it isn’t there.

Trait Implementations§

Source§

impl<T> FromIterator<T> for HandledHashMap<T>
where T: Handled + Eq + PartialEq + Hash,

Source§

fn from_iter<U: IntoIterator<Item = T>>(iter: U) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> Index<T> for HandledHashMap<T>
where T: Handled + Eq + PartialEq + Hash,

Source§

fn index(&self, index: T) -> &Self::Output

Get the handle associated with one of the collection’s items.

Source§

type Output = Handle<T>

The returned type after indexing.

Auto Trait Implementations§

§

impl<T> Freeze for HandledHashMap<T>

§

impl<T> RefUnwindSafe for HandledHashMap<T>

§

impl<T> Send for HandledHashMap<T>
where T: Send, <T as Handled>::HandleCoreType: Send,

§

impl<T> Sync for HandledHashMap<T>
where T: Sync, <T as Handled>::HandleCoreType: Sync,

§

impl<T> Unpin for HandledHashMap<T>
where T: Unpin, <T as Handled>::HandleCoreType: Unpin,

§

impl<T> UnwindSafe for HandledHashMap<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.