3 releases
0.1.2 | Nov 29, 2023 |
---|---|
0.1.1 | Nov 29, 2023 |
0.1.0 | Nov 29, 2023 |
#2120 in Data structures
9KB
Deferred Vector Library
Introduction
The Deferred Vector Library offers DeferredVec
, a generic, lazily-initialized vector structure in Rust, ideal for efficient resource management and performance optimization. Developed by Prof. Afonso Miguel at PUCPR.
Features
- Laziness: Only initializes the vector when explicitly accessed.
- Flexibility: Compatible with any type
T
that implements theClone
trait. - Custom Initialization: Uses a user-provided function for vector initialization.
Usage
Instantiate DeferredVec
with a fetch_function
defining the initial state. The vector remains uninitialized (None
) until methods like get
or len
are invoked, triggering initialization.
Examples
Basic usage:
let mut deferred_vector = DeferredVec::new(|| vec![1, 2, 3]);
assert_eq!(deferred_vector.is_deferred(), true);
Fetch de vector data:
assert_eq!(deferred_vector.len(), 3);
Check if the vector is not deferred:
let initialized_vector = deferred_vector.get();
assert_eq!(deferred_vector.is_deferred(), false);
Testing
Includes unit tests focusing on lazy initialization and basic vector operations.
Disclaimer
Provided as-is, without warranty. Test thoroughly before production use.
Author
Prof. Afonso Miguel - PUCPR.
License
MIT License - see the LICENSE file for details.