Debian Codegraph @

/

debian rust-inplace-vec-builder 0.1.1-1debian librust-inplace-vec-builder-dev debian librust-inplace-vec-builder+default-dev debian librust-inplace-vec-builder+smallvec-dev debian librust-inplace-vec-builder+stdvec-dev debian librust-inplace-vec-builder-0-dev debian librust-inplace-vec-builder-0+default-dev debian librust-inplace-vec-builder-0+smallvec-dev debian librust-inplace-vec-builder-0+stdvec-dev debian librust-inplace-vec-builder-0.1-dev debian librust-inplace-vec-builder-0.1+default-dev debian librust-inplace-vec-builder-0.1+smallvec-dev debian librust-inplace-vec-builder-0.1+stdvec-dev debian librust-inplace-vec-builder-0.1.1-dev debian librust-inplace-vec-builder-0.1.1+default-dev debian librust-inplace-vec-builder-0.1.1+smallvec-dev debian librust-inplace-vec-builder-0.1.1+stdvec-dev cargo inplace-vec-builder 0.1.1 debianjsonmakefilemarkdownrustrust-c-abishelltomlyaml 19 files · 217 symbols
View dependency graph

Depends on

  • debhelper (debhelper)
  • dh-cargo (dh-cargo)
  • cargo, librust-smallvec-1+default-dev, libstd-rust-dev, rustc
README (full)

Inplace-Vec-Builder

A small library to build a Vec or SmallVec out of itself without allocating.

This is useful when writing in place operations that do not allocate.

Imagine you have a vec that contains some numbers. You now want to apply some transformation on these elements, like mapping, filtering, adding some elements, and then store the result in the same place.

The simplest way to do this would be something like this:

        let mut res = self
            .elements
            .iter()
            .filter(|x| **x > 5)
            .map(|x| *x * 2)
            .chain(std::iter::once(123))
            .collect();
        std::mem::swap(&mut self.elements, &mut res);

But this does allocate a new vector. Usually not a big deal, but if this is some very frequently used code, you want to avoid it.

Note that in many cases where you do filtering combined with a transformation, retain can be used. If that is the case using retain is of course preferable.

This crate provides a helper that allows doing something like the above without allocations. It is fairly low level, since it is intended to be used from other libraries.

        let mut t = InPlaceVecBuilder::from(&mut self.elements);
        while let Some(elem) = t.pop_front() {
            if elem > 5 {
                t.push(elem * 2);
            }
        }
        t.push(123);

Features

  • stdvec (default): std Vec support
  • smallvec: SmallVec support
dir .github/
dir debian/
dir examples/
dir src/
file .cargo_vcs_info.json
file .gitignore
file Cargo.lock
file Cargo.toml
file Cargo.toml.orig
file README.md