univec 0.2.0

A vector that can hold elements of any single type
Documentation

A dynamic vector that can store elements of any single type.

Usage

UniVec is a dynamic vector that can store elements of any single type. It is similar to Vec<Box<dyn Any>>, but more lightweight.

UniVec is useful when you need to store elements of a single type, but you don't know the type at compile time.

Example

# use univec::UniVec;
let mut univec = UniVec::new();
univec.push(&42_i32);

let mut element = univec.get_mut::<i32>(0).unwrap();

if let Some(elem) = element {
    *elem += 10;
}

assert_eq!(univec.get::<i32>(0).unwrap(), Some(&52));

Performance

UniVec is a wrapper around dyn trait of a Vec. Most operations are just a single layer of indirection into the underlying Vec. Because of this, UniVec should have performance close to Vec.

Limitations

The main limitation of UniVec is that it can only store a single type of element. This is by design, as UniVec is intended to be a simple, flexible, and lightweight alternative to Vec<Box<dyn Any>>.

Fun Fact

This crates is a testbed for code and documentation generation with ChatGPT and Codepilot. Nevertheless all code is audited and tested.

Contribution

This crate is far from complete. Contributions are welcome! Feel free to open an issue or submit a pull request.

Credits

  • FSMaxB -- Implementation Idea about the helper trait.