[−][src]Struct cursed_collections::LazyArray
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 main() { let heap = LazyArray::<Entry>::new(10); 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
impl<T> LazyArray<T>
[src]
pub fn new(size: usize) -> LazyArray<T>
[src]
pub fn get_or_insert(&self, index: usize, t: T) -> &T
[src]
pub fn get(&self, index: usize) -> Option<&T>
[src]
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for LazyArray<T>
impl<T> Send for LazyArray<T> where
T: Send,
T: Send,
impl<T> !Sync for LazyArray<T>
impl<T> Unpin for LazyArray<T>
impl<T> UnwindSafe for LazyArray<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,