1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/// Trait for state-reading operations
pub trait StateAccess {
type Item;
type View;
type ReadState;
type Id;
/// Get a readable state for an item
fn read(id: Self::Id) -> Self::ReadState;
/// Iterate over all items in the state
fn iter<F, R>(f: F) -> Vec<R>
where
F: FnMut(&Self::Id, &Self::Item) -> R;
/// Get views of all items in the state
fn views() -> Vec<Self::View>;
/// Get the number of items in the state
fn len() -> u64;
}
/// Trait for state-modifying operations
pub trait StateMutations {
type Error;
type AddArgs;
type WriteState;
type Id;
/// Add a new item to the state
fn add(args: Self::AddArgs) -> Result<Self::Id, Self::Error>;
/// Get a writable state for an item
fn write(id: Self::Id) -> Self::WriteState;
/// Reset the entire state
fn reset();
}