pub struct LazyArray<T> { /* private fields */ }Expand description
A collection with a size defined at creation, but where entries are initialized later.
It is useful when you are reading nodes of an acyclic graph, where entries can be read as you need them.
§Example
#[derive(Debug, Eq, PartialEq)]
struct Entry<'heap> {
value: i32,
next: Option<&'heap Entry<'heap>>,
}
fn do_something<'heap>(heap: &'heap LazyArray<Entry<'heap>>) {
let entry_0 = heap.get_or_insert(3, Entry { value: 123, next: None });
let entry_1 = heap.get_or_insert(6, Entry { value: 456, next: Some(entry_0) });
assert_eq!(Some(123), entry_1.next.map(|inner| inner.value));
assert_eq!(None, heap.get(2));
}Implementations§
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for LazyArray<T>
impl<T> RefUnwindSafe for LazyArray<T>where
T: RefUnwindSafe,
impl<T> !Send for LazyArray<T>
impl<T> !Sync for LazyArray<T>
impl<T> Unpin for LazyArray<T>
impl<T> UnwindSafe for LazyArray<T>where
T: RefUnwindSafe,
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