[][src]Struct cursed_collections::LazyArray

pub struct LazyArray<T>(_);

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

impl<T: Debug> Debug for LazyArray<T>[src]

impl<T> Default for LazyArray<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for LazyArray<T>

impl<T> Send for LazyArray<T> where
    T: Send

impl<T> !Sync for LazyArray<T>

impl<T> Unpin for LazyArray<T>

impl<T> UnwindSafe for LazyArray<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.