Struct deferred_vector::DeferredVec
source · 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,
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.
sourcepub fn new(fetch_function: fn() -> Vec<T>) -> DeferredVec<T>
pub fn new(fetch_function: fn() -> Vec<T>) -> DeferredVec<T>
sourcepub fn get(&mut self) -> Vec<T>
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.
sourcepub fn len(&mut self) -> usize
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.
sourcepub fn is_deferred(&self) -> bool
pub fn is_deferred(&self) -> bool
Checks if the vector is initialized.
Returns
true if vec is None (not yet fetched) and false otherwise.