pub struct DeferredVec<T> { /* private fields */ }
Expand description

A generic struct DeferredVec for lazily initializing a vector.

This struct holds an Option<Vec<T>> to store the vector, which may or may not be present initially, and a fetch_function of type fn() -> Vec<T>, which is a function pointer that returns a vector of the same type when called.

Implementations§

source§

impl<T> DeferredVec<T>where T: Clone,

Implement methods for DeferredVec.

The #[allow(dead_code)] attribute indicates that even if some methods are not used, they should not be considered dead code. The generic type T is bound by the trait std::clone::Clone to ensure that elements of the vector can be cloned.

source

pub fn new(fetch_function: fn() -> Vec<T>) -> DeferredVec<T>

Constructs a new instance of DeferredVec.

Arguments
  • fetch_function - A function to initialize the vector.
Returns

A new instance of DeferredVec with vec initialized as None.

source

pub fn get(&mut self) -> Vec<T>

Fetches and returns the vector.

This method calls fetch and unwraps the result to get the vector. It panics if fetch returns None.

Returns

The fetched vector.

source

pub fn len(&mut self) -> usize

Returns the length of the fetched vector.

This method fetches the vector and returns its length. It panics if fetch returns None.

Returns

The length of the fetched vector.

source

pub fn is_deferred(&self) -> bool

Checks if the vector is initialized.

Returns

true if vec is None (not yet fetched) and false otherwise.

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for DeferredVec<T>where T: RefUnwindSafe,

§

impl<T> Send for DeferredVec<T>where T: Send,

§

impl<T> Sync for DeferredVec<T>where T: Sync,

§

impl<T> Unpin for DeferredVec<T>where T: Unpin,

§

impl<T> UnwindSafe for DeferredVec<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.