Aper
Aper is a data structure library in which every data structure is a state machine, and every mutation is a first-class value that can be serialized and sent over the network, or stored for later.
What is a state machine?
For the purposes of Aper, a state machine is simply a struct
or enum
that
implements StateMachine
and has the following properties:
- It defines a
StateMachine::Transition
type, through which every possible change to the state can be described. It is usually useful, though not required, that this be anenum
type. - It defines a
StateMachine::Conflict
type, which describes a conflict which may occur when a transition is applied that is not valid at the time it is applied. For simple types where a conflict is impossible, you can useNeverConflict
for this. - All state updates are deterministic: if you clone a
StateMachine
and aTransition
, the result of applying the cloned transition to the cloned state must be identical to applying the original transition to the original state.
Here's an example StateMachine
implementing a counter:
use ;
use ;
;
Why not CRDT?
Conflict-free replicated data types are a really neat way of representing data that's shared between peers. In order to avoid the need for a central “source of truth”, CRDTs require that update operations (i.e. state transitions) be commutative. This allows them to represent a bunch of common data structures, but doesn't allow you to represent arbitrarily complex update logic. By relying on a central authority, a state-machine approach allows you to implement data structures with arbitrary update logic, such as atomic moves of a value between two data structures, or the rules of a board game.
Aper is rapidly evolving. Consider this a technology preview. See the list of issues outstanding for version 1.0