deferred_vector

Crates.iodeferred_vector
lib.rsdeferred_vector
version0.1.2
sourcesrc
created_at2023-11-29 02:12:43.301345
updated_at2023-11-29 02:26:41.491012
descriptionA deferred vector implementation
homepage
repositoryhttps://github.com/afmiguel/deferred_vector
max_upload_size
id1052535
size9,201
Prof. Afonso Miguel - PUCPR (afmiguel)

documentation

https://docs.rs/deferred_vector

README

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 the Clone 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.

Commit count: 8

cargo fmt