[−][src]Trait heapnotize::Rack
A trait specifying functions and methods for initialization of a Rack
and
for storing values in it.
Capacity
A Rack
keep an allocated memory on the stack for values to be stored in.
It has several implementations varying in the capacity they provide:
Rack1
, Rack2
,
Rack4
, Rack8
,
Rack16
, Rack32
, ... ,
Rack1024
.
Stored type
It can store only a single type of values it is initialized with. The type
can be specified during initialization Rack64::<i32>
, but Rust is usually
able to deduce the type on its own based on the code adding values to the
Rack
.
Memory requirements
Unlike a basic array, Rack
is not zero-cost when it comes to memory
requirements. The formula for the memory requirements of a rack is
following:
capacity_of_the_rack * (round_up_to_the_closest_multiple_of_8(size_of(value)) + 8)
Required methods
fn add(&self, value: T) -> Result<Unit<'_, T>, AddUnitError>
Add a value to the Rack
and return an error if it is full.
Errors
This method will return an error in case the Rack
is fully populated.
If you don't expect it to ever fail, use
must_add
instead.
Examples
Initialize the Rack and add an integer to it. Notice that since Rust can
deduce the T
of Rack<T>
based on the value in add
, there is no
need to specify the type during the initialization:
let rack = Rack64::new(); let five = rack.must_add(5);
fn must_add(&self, value: T) -> Unit<'_, T>
Add a value to the Rack
and panic if it is full.
Panics
This method will panic in case the Rack
is fully populated. If you
would rather receive an error, use add
instead.
Examples
Initialize the Rack and add an integer to it. Notice that since Rust can
deduce the T
of Rack<T>
based on the value in add
, there is no
need to specify the type during the initialization:
let rack = Rack64::new(); let five = rack.add(5).unwrap();