index-pool

Crates.ioindex-pool
lib.rsindex-pool
version1.0.11
sourcesrc
created_at2017-08-25 03:37:04.500261
updated_at2018-05-10 08:52:11.916762
descriptionA pool which manages allocation of unique indices. Acts like a psuedo-memory allocator.
homepage
repositoryhttps://github.com/Connicpu/index-pool
max_upload_size
id28901
size18,131
Connie Hilarides (Connicpu)

documentation

https://docs.rs/index-pool

README

index-pool index-pool on crates.io Build Status Build status

A pool which manages allocation of unique indices. Acts like a psuedo-memory allocator.

[dependencies]
index-pool = "1.0"

Example

extern crate index_pool;
use index_pool::IndexPool;

fn main() {
    let mut pool = IndexPool::new();

    let a = pool.new_id();
    let b = pool.new_id();
    let c = pool.new_id();

    let mut data = vec![""; pool.maximum()];
    data[a] = "apple";
    data[b] = "banana";
    data[c] = "coconut";

    // Nevermind, no bananas
    pool.return_id(b).unwrap();

    let p = pool.new_id();
    data[p] = "pineapple";

    assert_eq!(data, vec!["apple", "pineapple", "coconut"]);
}
Commit count: 25

cargo fmt