@@ -17,11 +17,11 @@ use futures::StreamExt;
1717use  serde:: { Deserialize ,  Serialize } ; 
1818
1919mod  mem; 
20- pub  use  mem:: MemoryStorage ; 
20+ pub  use  mem:: MemoryStore ; 
2121mod  nats; 
22- pub  use  nats:: NATSStorage ; 
22+ pub  use  nats:: NATSStore ; 
2323mod  etcd; 
24- pub  use  etcd:: EtcdStorage ; 
24+ pub  use  etcd:: EtcdStore ; 
2525
2626/// A key that is safe to use directly in the KV store. 
2727#[ derive( Debug ,  Clone ,  PartialEq ) ]  
@@ -69,12 +69,12 @@ pub trait KeyValueStore: Send + Sync {
6969        bucket_name :  & str , 
7070        // auto-delete items older than this 
7171        ttl :  Option < Duration > , 
72-     )  -> Result < Box < dyn  KeyValueBucket > ,  StorageError > ; 
72+     )  -> Result < Box < dyn  KeyValueBucket > ,  StoreError > ; 
7373
7474    async  fn  get_bucket ( 
7575        & self , 
7676        bucket_name :  & str , 
77-     )  -> Result < Option < Box < dyn  KeyValueBucket > > ,  StorageError > ; 
77+     )  -> Result < Option < Box < dyn  KeyValueBucket > > ,  StoreError > ; 
7878
7979    fn  connection_id ( & self )  -> u64 ; 
8080} 
@@ -90,7 +90,7 @@ impl KeyValueStoreManager {
9090        & self , 
9191        bucket :  & str , 
9292        key :  & Key , 
93-     )  -> Result < Option < T > ,  StorageError >  { 
93+     )  -> Result < Option < T > ,  StoreError >  { 
9494        let  Some ( bucket)  = self . 0 . get_bucket ( bucket) . await ? else  { 
9595            // No bucket means no cards 
9696            return  Ok ( None ) ; 
@@ -103,7 +103,7 @@ impl KeyValueStoreManager {
103103            Ok ( None )  => Ok ( None ) , 
104104            Err ( err)  => { 
105105                // TODO look at what errors NATS can give us and make more specific wrappers 
106-                 Err ( StorageError :: NATSError ( err. to_string ( ) ) ) 
106+                 Err ( StoreError :: NATSError ( err. to_string ( ) ) ) 
107107            } 
108108        } 
109109    } 
@@ -116,7 +116,7 @@ impl KeyValueStoreManager {
116116        bucket_name :  & str , 
117117        bucket_ttl :  Option < Duration > , 
118118    )  -> ( 
119-         tokio:: task:: JoinHandle < Result < ( ) ,  StorageError > > , 
119+         tokio:: task:: JoinHandle < Result < ( ) ,  StoreError > > , 
120120        tokio:: sync:: mpsc:: UnboundedReceiver < T > , 
121121    )  { 
122122        let  bucket_name = bucket_name. to_string ( ) ; 
@@ -141,7 +141,7 @@ impl KeyValueStoreManager {
141141                let  _ = tx. send ( card) ; 
142142            } 
143143
144-             Ok :: < ( ) ,  StorageError > ( ( ) ) 
144+             Ok :: < ( ) ,  StoreError > ( ( ) ) 
145145        } ) ; 
146146        ( watch_task,  rx) 
147147    } 
@@ -152,14 +152,14 @@ impl KeyValueStoreManager {
152152        bucket_ttl :  Option < Duration > , 
153153        key :  & Key , 
154154        obj :  & mut  T , 
155-     )  -> anyhow:: Result < StorageOutcome >  { 
155+     )  -> anyhow:: Result < StoreOutcome >  { 
156156        let  obj_json = serde_json:: to_string ( obj) ?; 
157157        let  bucket = self . 0 . get_or_create_bucket ( bucket_name,  bucket_ttl) . await ?; 
158158
159159        let  outcome = bucket. insert ( key,  & obj_json,  obj. revision ( ) ) . await ?; 
160160
161161        match  outcome { 
162-             StorageOutcome :: Created ( revision)  | StorageOutcome :: Exists ( revision)  => { 
162+             StoreOutcome :: Created ( revision)  | StoreOutcome :: Exists ( revision)  => { 
163163                obj. set_revision ( revision) ; 
164164            } 
165165        } 
@@ -178,43 +178,43 @@ pub trait KeyValueBucket: Send {
178178        key :  & Key , 
179179        value :  & str , 
180180        revision :  u64 , 
181-     )  -> Result < StorageOutcome ,   StorageError > ; 
181+     )  -> Result < StoreOutcome ,   StoreError > ; 
182182
183183    /// Fetch an item from the key-value storage 
184- async  fn  get ( & self ,  key :  & Key )  -> Result < Option < bytes:: Bytes > ,  StorageError > ; 
184+ async  fn  get ( & self ,  key :  & Key )  -> Result < Option < bytes:: Bytes > ,  StoreError > ; 
185185
186186    /// Delete an item from the bucket 
187- async  fn  delete ( & self ,  key :  & Key )  -> Result < ( ) ,  StorageError > ; 
187+ async  fn  delete ( & self ,  key :  & Key )  -> Result < ( ) ,  StoreError > ; 
188188
189189    /// A stream of items inserted into the bucket. 
190190/// Every time the stream is polled it will either return a newly created entry, or block until 
191191/// such time. 
192192async  fn  watch ( 
193193        & self , 
194-     )  -> Result < Pin < Box < dyn  futures:: Stream < Item  = bytes:: Bytes >  + Send  + ' life0 > > ,  StorageError > ; 
194+     )  -> Result < Pin < Box < dyn  futures:: Stream < Item  = bytes:: Bytes >  + Send  + ' life0 > > ,  StoreError > ; 
195195
196-     async  fn  entries ( & self )  -> Result < HashMap < String ,  bytes:: Bytes > ,  StorageError > ; 
196+     async  fn  entries ( & self )  -> Result < HashMap < String ,  bytes:: Bytes > ,  StoreError > ; 
197197} 
198198
199199#[ derive( Debug ,  Copy ,  Clone ,  Eq ,  PartialEq ) ]  
200- pub  enum  StorageOutcome  { 
200+ pub  enum  StoreOutcome  { 
201201    /// The operation succeeded and created a new entry with this revision. 
202202/// Note that "create" also means update, because each new revision is a "create". 
203203Created ( u64 ) , 
204204    /// The operation did not do anything, the value was already present, with this revision. 
205205Exists ( u64 ) , 
206206} 
207- impl  fmt:: Display  for  StorageOutcome  { 
207+ impl  fmt:: Display  for  StoreOutcome  { 
208208    fn  fmt ( & self ,  f :  & mut  fmt:: Formatter < ' _ > )  -> fmt:: Result  { 
209209        match  self  { 
210-             StorageOutcome :: Created ( revision)  => write ! ( f,  "Created at {revision}" ) , 
211-             StorageOutcome :: Exists ( revision)  => write ! ( f,  "Exists at {revision}" ) , 
210+             StoreOutcome :: Created ( revision)  => write ! ( f,  "Created at {revision}" ) , 
211+             StoreOutcome :: Exists ( revision)  => write ! ( f,  "Exists at {revision}" ) , 
212212        } 
213213    } 
214214} 
215215
216216#[ derive( thiserror:: Error ,  Debug ) ]  
217- pub  enum  StorageError  { 
217+ pub  enum  StoreError  { 
218218    #[ error( "Could not find bucket '{0}'" ) ]  
219219    MissingBucket ( String ) , 
220220
@@ -293,12 +293,12 @@ mod tests {
293293    async  fn  test_memory_storage ( )  -> anyhow:: Result < ( ) >  { 
294294        init ( ) ; 
295295
296-         let  s = Arc :: new ( MemoryStorage :: new ( ) ) ; 
296+         let  s = Arc :: new ( MemoryStore :: new ( ) ) ; 
297297        let  s2 = Arc :: clone ( & s) ; 
298298
299299        let  bucket = s. get_or_create_bucket ( BUCKET_NAME ,  None ) . await ?; 
300300        let  res = bucket. insert ( & "test1" . into ( ) ,  "value1" ,  0 ) . await ?; 
301-         assert_eq ! ( res,  StorageOutcome :: Created ( 0 ) ) ; 
301+         assert_eq ! ( res,  StoreOutcome :: Created ( 0 ) ) ; 
302302
303303        let  ( got_first_tx,  got_first_rx)  = tokio:: sync:: oneshot:: channel ( ) ; 
304304        let  ingress = tokio:: spawn ( async  move  { 
@@ -317,27 +317,27 @@ mod tests {
317317            let  v = stream. next ( ) . await . unwrap ( ) ; 
318318            assert_eq ! ( v,  "value3" . as_bytes( ) ) ; 
319319
320-             Ok :: < _ ,  StorageError > ( ( ) ) 
320+             Ok :: < _ ,  StoreError > ( ( ) ) 
321321        } ) ; 
322322
323-         // MemoryStorage  uses a HashMap with no inherent ordering, so we must ensure test1 is 
323+         // MemoryStore  uses a HashMap with no inherent ordering, so we must ensure test1 is 
324324        // fetched before test2 is inserted, otherwise they can come out in any order, and we 
325325        // wouldn't be testing the watch behavior. 
326326        got_first_rx. await ?; 
327327
328328        let  res = bucket. insert ( & "test2" . into ( ) ,  "value2" ,  0 ) . await ?; 
329-         assert_eq ! ( res,  StorageOutcome :: Created ( 0 ) ) ; 
329+         assert_eq ! ( res,  StoreOutcome :: Created ( 0 ) ) ; 
330330
331331        // Repeat a key and revision. Ignored. 
332332        let  res = bucket. insert ( & "test2" . into ( ) ,  "value2" ,  0 ) . await ?; 
333-         assert_eq ! ( res,  StorageOutcome :: Exists ( 0 ) ) ; 
333+         assert_eq ! ( res,  StoreOutcome :: Exists ( 0 ) ) ; 
334334
335335        // Increment revision 
336336        let  res = bucket. insert ( & "test2" . into ( ) ,  "value2" ,  1 ) . await ?; 
337-         assert_eq ! ( res,  StorageOutcome :: Created ( 1 ) ) ; 
337+         assert_eq ! ( res,  StoreOutcome :: Created ( 1 ) ) ; 
338338
339339        let  res = bucket. insert ( & "test3" . into ( ) ,  "value3" ,  0 ) . await ?; 
340-         assert_eq ! ( res,  StorageOutcome :: Created ( 0 ) ) ; 
340+         assert_eq ! ( res,  StoreOutcome :: Created ( 0 ) ) ; 
341341
342342        // ingress exits once it has received all values 
343343        let  _ = ingress. await ?; 
@@ -349,12 +349,12 @@ mod tests {
349349    async  fn  test_broadcast_stream ( )  -> anyhow:: Result < ( ) >  { 
350350        init ( ) ; 
351351
352-         let  s:  & ' static  _  = Box :: leak ( Box :: new ( MemoryStorage :: new ( ) ) ) ; 
352+         let  s:  & ' static  _  = Box :: leak ( Box :: new ( MemoryStore :: new ( ) ) ) ; 
353353        let  bucket:  & ' static  _  =
354354            Box :: leak ( Box :: new ( s. get_or_create_bucket ( BUCKET_NAME ,  None ) . await ?) ) ; 
355355
356356        let  res = bucket. insert ( & "test1" . into ( ) ,  "value1" ,  0 ) . await ?; 
357-         assert_eq ! ( res,  StorageOutcome :: Created ( 0 ) ) ; 
357+         assert_eq ! ( res,  StoreOutcome :: Created ( 0 ) ) ; 
358358
359359        let  stream = bucket. watch ( ) . await ?; 
360360        let  tap = TappableStream :: new ( stream,  10 ) . await ; 
0 commit comments