pub struct HandledVec<T>where
T: Handled,{ /* private fields */ }Expand description
A collection of Handled instances with automatically-generated handles, supporting efficient handle-to-instance 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 handle-to-instance lookup.
This usually serves for generating handles to instances of complex data types.
§Example
struct LinkedListNode {
num: u32,
next: Option<Handle<LinkedListNode>>,
}
impl Handled for LinkedListNode { type HandleCoreType = u8; }
let mut nodes = HandledVec::new();
let tail_handle = nodes.insert(LinkedListNode { num: 1337, next: None });
let head_handle = nodes.insert(LinkedListNode { num: 42, next: Some(tail_handle) });Implementations§
Source§impl<T> HandledVec<T>where
T: Handled,
impl<T> HandledVec<T>where
T: Handled,
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new, empty, HandledVec.
Sourcepub fn insert(&mut self, item: T) -> Handle<T>
pub fn insert(&mut self, item: T) -> Handle<T>
Adds a new item into the collection, and returns its newly generated handle.
Sourcepub fn list_handles(&self) -> impl Iterator<Item = Handle<T>>
pub fn list_handles(&self) -> impl Iterator<Item = Handle<T>>
Lists the handles to all available items in the collection.
Trait Implementations§
Source§impl<T> Clone for HandledVec<T>
impl<T> Clone for HandledVec<T>
Source§fn clone(&self) -> HandledVec<T>
fn clone(&self) -> HandledVec<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T> Debug for HandledVec<T>
impl<T> Debug for HandledVec<T>
Source§impl<'a, T> FromIterator<T> for HandledVec<T>where
T: Handled,
impl<'a, T> FromIterator<T> for HandledVec<T>where
T: Handled,
Source§fn from_iter<U: IntoIterator<Item = T>>(iter: U) -> Self
fn from_iter<U: IntoIterator<Item = T>>(iter: U) -> Self
Creates a value from an iterator. Read more
Source§impl<'a, T> IntoIterator for &'a HandledVec<T>where
T: Handled,
impl<'a, T> IntoIterator for &'a HandledVec<T>where
T: Handled,
Source§impl<'a, T> IntoIterator for &'a mut HandledVec<T>where
T: Handled,
impl<'a, T> IntoIterator for &'a mut HandledVec<T>where
T: Handled,
Source§impl<T> PartialEq for HandledVec<T>
impl<T> PartialEq for HandledVec<T>
impl<T> Eq for HandledVec<T>
impl<T> StructuralPartialEq for HandledVec<T>where
T: Handled,
Auto Trait Implementations§
impl<T> Freeze for HandledVec<T>
impl<T> RefUnwindSafe for HandledVec<T>where
T: RefUnwindSafe,
impl<T> Send for HandledVec<T>where
T: Send,
impl<T> Sync for HandledVec<T>where
T: Sync,
impl<T> Unpin for HandledVec<T>where
T: Unpin,
impl<T> UnwindSafe for HandledVec<T>where
T: UnwindSafe,
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