heaparray
This crate aims to give people better control of how they allocate memory, by providing a customizable way to allocate blocks of memory, that optionally contains metadata about the block itself. This makes it much easier to implement Dynamically-Sized Types (DSTs), and also reduces the number of pointer indirections necessary to share data between threads.
Features
- Safe API to dynamically-sized types
- Generic implementations of common tasks so you can customize the implementation of a type without having to write additional boilerplate
- Atomically reference-counted memory blocks of arbitrary size without
using a
Vec
; this means you can access reference-counted memory with only a single pointer indirection.
Examples
Creating an array:
use *;
let len = 10;
let array = new;
assert!;
Indexing works as you would expect:
use *;
let mut array = new;
array = 2;
assert!;
Additionally, you can customize what information should be stored alongside
the elements in the array using the HeapArray::with_label
function:
let mut array = with_label;
Dynamically Sized Types
The Rust documentation on exotically sized types, at the end of the section on dynamically-sized types states that:
Currently the only properly supported way to create a custom DST is by making your type generic and performing an unsizing coercion... (Yes, custom DSTs are a largely half-baked feature for now.)
This crate aims to provide some of that functionality; the code that the docs give is the following:
using this crate, the MySuperSliceable<[u8]>
type would be
implemented like this:
use *;
type MySuperSliceable = ;
License: MIT