19
19
//! into the event cache for the actual storage. By default this brings an
20
20
//! in-memory store.
21
21
22
- use std:: { str:: Utf8Error , sync:: Arc } ;
22
+ use std:: { fmt , str:: Utf8Error , sync:: Arc } ;
23
23
24
24
#[ cfg( any( test, feature = "testing" ) ) ]
25
25
#[ macro_use]
26
26
pub mod integration_tests;
27
27
mod memory_store;
28
28
mod traits;
29
29
30
- use matrix_sdk_common:: store_locks:: BackingStore ;
30
+ use matrix_sdk_common:: store_locks:: { BackingStore , CrossProcessStoreLock } ;
31
31
pub use matrix_sdk_store_encryption:: Error as StoreEncryptionError ;
32
32
33
33
#[ cfg( any( test, feature = "testing" ) ) ]
@@ -85,10 +85,8 @@ impl EventCacheStoreError {
85
85
/// An `EventCacheStore` specific result type.
86
86
pub type Result < T , E = EventCacheStoreError > = std:: result:: Result < T , E > ;
87
87
88
- /// The public API to read the event cache store: it is behind a cross-process
89
- /// lock.
90
88
#[ derive( Clone , Debug ) ]
91
- pub struct LockableEventCacheStore ( Arc < dyn EventCacheStore < Error = EventCacheStoreError > > ) ;
89
+ struct LockableEventCacheStore ( Arc < DynEventCacheStore > ) ;
92
90
93
91
#[ cfg_attr( target_arch = "wasm32" , async_trait:: async_trait( ?Send ) ) ]
94
92
#[ cfg_attr( not( target_arch = "wasm32" ) , async_trait:: async_trait) ]
@@ -104,3 +102,32 @@ impl BackingStore for LockableEventCacheStore {
104
102
self . 0 . try_take_leased_lock ( lease_duration_ms, key, holder) . await
105
103
}
106
104
}
105
+
106
+ /// The high-level public type to represent an `EventCacheStore` lock.
107
+ pub struct EventCacheStoreLock {
108
+ cross_process_lock : CrossProcessStoreLock < LockableEventCacheStore > ,
109
+ store : Arc < DynEventCacheStore > ,
110
+ }
111
+
112
+ impl fmt:: Debug for EventCacheStoreLock {
113
+ fn fmt ( & self , formatter : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
114
+ formatter. debug_struct ( "EventCacheStoreLock" ) . finish_non_exhaustive ( )
115
+ }
116
+ }
117
+
118
+ impl EventCacheStoreLock {
119
+ pub fn new ( store : Arc < DynEventCacheStore > , key : String , holder : String ) -> Self {
120
+ Self {
121
+ cross_process_lock : CrossProcessStoreLock :: new (
122
+ LockableEventCacheStore ( store. clone ( ) ) ,
123
+ key,
124
+ holder,
125
+ ) ,
126
+ store,
127
+ }
128
+ }
129
+
130
+ pub async fn lock ( & self ) -> & Arc < DynEventCacheStore > {
131
+ todo ! ( )
132
+ }
133
+ }
0 commit comments