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
use base::Result;
use base::FixedSize;
use base::Datable;
pub trait Committable<P, C>
where P: Datable,
C: Datable + FixedSize,
Self: 'static + Sized
{
fn commit_cb(&self, params: &P, cb: &Fn(&Self, &P) -> Result<C>) -> Result<C> {
cb(self, params)
}
fn verify_commit_cb(&self, params: &P, commit: &C, cb: &Fn(&Self, &P, &C) -> Result<bool>)
-> Result<bool>
{
cb(self, params, commit)
}
fn check_commit_cb(&self, params: &P, commit: &C, cb: &Fn(&Self, &P, &C) -> Result<bool>)
-> Result<()>
{
if !Self::verify_commit_cb(self, params, commit, cb)? {
return Err(String::from("invalid commit"));
}
Ok(())
}
}