Crate slice_pool [] [src]

This crate provides functionality for using a sliceable type as the underlying memory for a pool.

The allocated memory can be a mutable slice of any type.

use slice_pool::SlicePool;

let values = vec![10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
let mut memory = SlicePool::new(values);
assert_eq!(memory.len(), 10);

// Not enough memory available (only 10 elements)
assert!(memory.allocate(11).is_none());

let mut first = memory.allocate(2).unwrap();
assert_eq!(*first, [10, 20]);
first[1] = 15;
assert_eq!(*first, [10, 15]);

let mem2 = memory.allocate(5).unwrap();
assert_eq!(*mem2, [30, 40, 50, 60, 70]);

Structs

PoolRef

A reference to an allocated chunk, that acts as a slice.

PoolVal

An allocated chunk, that acts as a slice.

SlicePool

A thread-safe interface for allocating chunks in an owned slice.

SlicePoolRef

An interface for allocating chunks in a referenced slice.

Traits

Sliceable

Interface for any object compatible with SlicePool.