#numbers #heap-allocation #vec #stack #contain

one-stack-vec

OneStackVec could contain any number of item like Vec, and it does heap allocation only when it contains more than one item

3 unstable releases

Uses old Rust 2015

0.5.1 Jun 22, 2017
0.5.0 Jun 19, 2017
0.4.0 Jun 12, 2017

#2201 in Data structures

MIT/Apache

9KB
224 lines

One-Stack-Vec

Overview

OneStackVec is simple data structure which contains any number of items. It does not heap allocation until there is one or zero item.

How to use

// Initialize
let mut items = OneStackVec::new();

// Adding
items.add(42);

// Getting
assert_eq!(Some(&42), items.get(0));

// Removing
assert_eq!(Some(&42), items.remove(0));
assert_eq!(None, items.get(0));

lib.rs:

OneStackVec is simple data structure which contains any number of items. If there is one or zero item, ALO does not heap allocate. If there is more than one items, ALO does heap allocate.

Examples

use one_stack_vec::OneStackVec;

let mut items = OneStackVec::new();

// Adding
items.push(42);

// Getting
assert_eq!(Some(&42), items.get(0));

// Removing
assert_eq!(Some(42), items.pop());
assert_eq!(None, items.pop());

Dependencies

~110–350KB