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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use async_trait::async_trait;
use destream::en;
use sha2::digest::Output;
use sha2::Sha256;
use tc_error::*;
use tcgeneric::Id;
mod id;
pub mod fs;
pub mod lock {
use super::TxnId;
pub use txn_lock::{
Error as TxnLockError,
TxnLockFinalize, TxnLockReadGuard, TxnLockReadGuardExclusive, TxnLockRollback,
TxnLockWriteGuard,
};
pub type TxnLock<T> = txn_lock::TxnLock<TxnId, T>;
pub type TxnLockCommit<T> = txn_lock::TxnLockCommit<TxnId, T>;
}
pub use id::{TxnId, MIN_ID};
#[async_trait]
pub trait AsyncHash<D: fs::Dir> {
type Txn: Transaction<D>;
async fn hash(self, txn: &Self::Txn) -> TCResult<Output<Sha256>>;
}
#[async_trait]
pub trait IntoView<'en, D: fs::Dir> {
type Txn: Transaction<D>;
type View: en::IntoStream<'en> + Sized + 'en;
async fn into_view(self, txn: Self::Txn) -> TCResult<Self::View>;
}
#[async_trait]
pub trait Transact {
type Commit: Send + Sync;
async fn commit(&self, txn_id: TxnId) -> Self::Commit;
async fn rollback(&self, txn_id: &TxnId);
async fn finalize(&self, txn_id: &TxnId);
}
#[async_trait]
pub trait Transaction<D: fs::Dir>: Clone + Sized + Send + Sync + 'static {
fn id(&'_ self) -> &'_ TxnId;
fn context(&'_ self) -> &'_ D;
async fn subcontext(&self, id: Id) -> TCResult<Self>;
async fn subcontext_unique(&self) -> TCResult<Self>;
}