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
use mkit::{
    cbor::{FromCbor, IntoCbor},
    Cborize,
};

#[allow(unused_imports)]
use crate::wral::Wal;
use crate::{entry::Entry, Result};

/// Callback trait for updating application state in relation to [Wal] type.
pub trait State: 'static + Clone + Sync + Send + IntoCbor + FromCbor {
    fn on_add_entry(&mut self, new_entry: &Entry) -> Result<()>;
}

/// Default parameter, implementing [State] trait, for [Wal] type.
#[derive(Clone, Eq, PartialEq, Debug, Cborize)]
pub struct NoState;

impl NoState {
    const ID: u32 = 0x0;
}

impl State for NoState {
    fn on_add_entry(&mut self, _: &Entry) -> Result<()> {
        Ok(())
    }
}