[][src]Crate nested

A two dimensional collection whose purpose it to reduce heap allocations.

This crate is intended to be used when:

  • you want a potentially large:
    • Vec<String>
    • Vec<Vec<T>>
    • Vec<C> where C is heap allocated, dynamically sized and can implement Collection trait
  • you actually only need to use borrowed items (&[T] or &str)

Instead of having n + 1 allocations, you'll only have 2.

Example

use nested::Nested;

let mut v = Nested::<String>::new();

// you can either populate it one by one
v.push("a");
v.push("bb".to_string());
v.push("hhh");
v.extend(vec!["iiiiii".to_string(), "jjjj".to_string()]);
assert_eq!(v.len(), 5);
assert_eq!(&v[0], "a");
assert_eq!(&v[1], "bb");

// or you can directly collect it
let mut v = ["a", "b", "c", "d", "e", "f", "g"].iter().collect::<Nested<String>>();
assert_eq!(v.len(), 7);

// it also provides basic operations
let u = v.split_off(2);
assert_eq!(u.get(0), Some("c"));

v.truncate(1);
assert_eq!(v.pop(), Some("a".to_string()));
assert_eq!(v.pop(), None);

Structs

Iter

An iterator over Nested elements

Nested

A two dimensional collection with minimal allocation

Traits

Collection

A Collection trait to expose basic required fn for Nested to work properly

Type Definitions

Item

A Nested item when T: Collection

ZString

A Nested<String>

ZVec

A Nested<Vec<T>>