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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use casper_types::bytesrepr::Bytes;
pub mod in_memory;
pub mod lmdb;
pub trait Transaction: Sized {
type Error;
type Handle;
fn commit(self) -> Result<(), Self::Error>;
fn abort(self) {
unimplemented!("Abort operations should be performed in Drop implementations.")
}
}
pub trait Readable: Transaction {
fn read(&self, handle: Self::Handle, key: &[u8]) -> Result<Option<Bytes>, Self::Error>;
}
pub trait Writable: Transaction {
fn write(&mut self, handle: Self::Handle, key: &[u8], value: &[u8]) -> Result<(), Self::Error>;
}
pub trait TransactionSource<'a> {
type Error;
type Handle;
type ReadTransaction: Readable<Error = Self::Error, Handle = Self::Handle>;
type ReadWriteTransaction: Readable<Error = Self::Error, Handle = Self::Handle>
+ Writable<Error = Self::Error, Handle = Self::Handle>;
fn create_read_txn(&'a self) -> Result<Self::ReadTransaction, Self::Error>;
fn create_read_write_txn(&'a self) -> Result<Self::ReadWriteTransaction, Self::Error>;
}