A no_std crate for a fixed-size statically allocated ring-buffer with optional serde
(De)-Serialization.
|
|
Motivation
During my development of celluar_raza, I implemented various
numerical solvers.
One of them was the Adams-Bashforth solver for updating position and velocities of the individual
agents.
This solver utilizes a number of previously saved integration steps N.
Since cellular_raza aims to provide flexibility in model design, the type which represents the
position or velocity of the agent must be generic.
Furthermore, since this solver only requires the last N steps, we can overwrite any step before
that.
This leads to the Ringbuffer datastructure.
My main problem with existing solutions was that none provided statically-sized buffers which are
very important for performance and many did not have support for serde which I am using
extensively.
Design
This leads us to a datastructure which holds N elements of generic type T.
For efficient access, cache locality and efficient iteration, I chose a generic array [T; N] as
the underlying type.
Together with two internal counters of type usize, this is a very small memory footprint.
To iterate over this datastructure, I had to implement a custom type which is returned by the
IntoIterator trait.
Finally, implementing serde was a simply matter of deriving it.