vec_storage_reuse 0.1.0

Provides an API to reuse a `Vec`'s allocation
Documentation
  • Coverage
  • 55.56%
    5 out of 9 items documented1 out of 9 items with examples
  • Size
  • Source code size: 14.8 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.09 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Ten0/vec_storage_reuse
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Ten0

vec_storage_reuse

Crates.io License

Provides an API to reuse a Vec's allocation.

This is useful to achieve zero-alloc when storing data with short lifetimes in a Vec:

    let mut objects_storage: VecStorageForReuse<Object<'static>> = VecStorageForReuse::new();

    while let Some(byte_chunk) = stream.next() { // byte_chunk only lives this scope
        let mut objects: &mut Vec<Object<'_>> = &mut *objects_storage.reuse_allocation();

        // Zero-copy parsing; Object has references to chunk
        deserialize(byte_chunk, &mut objects)?;
        process(&objects)?;
    } // byte_chunk lifetime ends

Credits:

This crate delegates the actual unsafe functionality to the recycle_vec crate, and just provides an interface that abstracts the swapping with the container through Drop, so that one can never forget to swap back the temporary object with the storage