Crate heapnotize

Crate heapnotize 

Source
Expand description

A Rust library providing memory allocation on the stack.

§Initializing memory

In order to allocate values on the stack, Rack needs to be initialized first. A Rack is initialized with a type of values it can store and with a maximum number of values it can store. The Rack will occupy its full size in the memory, so choose the capacity wisely. Unlike Box, a Rack can store only values of a single type. In case you want to store different types, define multiple instances of Rack. There are several implementations of Rack available with capacities of powers of 2, up to 1024: Rack1, Rack2, Rack4, Rack8, Rack16, Rack32, … , Rack1024.

Learn more in the documentation of the Rack trait.

§Storing and accessing values

After the Rack is initalized, it is possible to store values on it. When a value is stored, a Unit struct is returned. A Unit provides an ownership of the value. Moreover, the value can be accessed through it, both mutably and immutably. Once Unit gets out of scope, it will make sure that the stored value gets dropped.

Learn more in the documentation of the Unit struct.

§Examples

Store a numeric value on the Rack and access it through the Unit:

let rack = Rack64::new();
let five = rack.must_add(5);
assert_eq!(*five, 5);

Use Unit to compose a recursive type:

enum List<'a> {
    Cons(i32, Unit<'a, List<'a>>),
    Nil,
}

use List::{Cons, Nil};

let rack = Rack64::new();
let list = Cons(1, rack.must_add(Cons(2, rack.must_add(Cons(3, rack.must_add(Nil))))));

See more examples in the documentation of the Rack trait and the Unit struct.

Structs§

Rack1
Implementation of Rack trait holding up to N values of a type T.
Rack2
Implementation of Rack trait holding up to N values of a type T.
Rack4
Implementation of Rack trait holding up to N values of a type T.
Rack8
Implementation of Rack trait holding up to N values of a type T.
Rack16
Implementation of Rack trait holding up to N values of a type T.
Rack32
Implementation of Rack trait holding up to N values of a type T.
Rack64
Implementation of Rack trait holding up to N values of a type T.
Rack128
Implementation of Rack trait holding up to N values of a type T.
Rack256
Implementation of Rack trait holding up to N values of a type T.
Rack512
Implementation of Rack trait holding up to N values of a type T.
Rack1024
Implementation of Rack trait holding up to N values of a type T.
Unit
A type serving as an owner of a value stored on the Rack.

Enums§

AddUnitError
An enumeration of possible errors which can happen when adding a new value to a Rack.

Traits§

Rack
A trait specifying functions and methods for initialization of a Rack and for storing values in it.