@@ -99,13 +99,11 @@ pub trait StorageConfigTrait:
9999 Clone + Debug + Serialize + PartialEq + Validate + SerializeConfig + Default + Send + Sync
100100{
101101}
102- /// A trait for the storage. Does not assume concurrent access is possible - see [AsyncStorage].
103- pub trait Storage : Send + Sync {
104- type Stats : StorageStats ;
105- type Config : StorageConfigTrait ;
106102
103+ /// A read-only view of a storage. Does not assume concurrent access is possible.
104+ pub trait ReadOnlyStorage : Send + Sync {
107105 /// Returns value from storage, if it exists.
108- /// Uses a mutable &self to allow changes in the internal state of the storage (e.g.,
106+ /// Uses a mutable ` &self` to allow changes in the internal state of the storage (e.g.,
109107 /// for caching).
110108 // Use explicit desugaring of `async fn` to allow adding trait bounds to the return type, see
111109 // https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html#async-fn-in-public-traits
@@ -115,16 +113,6 @@ pub trait Storage: Send + Sync {
115113 key : & DbKey ,
116114 ) -> impl Future < Output = PatriciaStorageResult < Option < DbValue > > > + Send ;
117115
118- /// Sets value in storage. If key already exists, its value is overwritten.
119- // Use explicit desugaring of `async fn` to allow adding trait bounds to the return type, see
120- // https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html#async-fn-in-public-traits
121- // for details.
122- fn set (
123- & mut self ,
124- key : DbKey ,
125- value : DbValue ,
126- ) -> impl Future < Output = PatriciaStorageResult < ( ) > > + Send ;
127-
128116 /// Returns values from storage in same order of given keys. Value is None for keys that do not
129117 /// exist.
130118 // Use explicit desugaring of `async fn` to allow adding trait bounds to the return type, see
@@ -134,6 +122,22 @@ pub trait Storage: Send + Sync {
134122 & mut self ,
135123 keys : & [ & DbKey ] ,
136124 ) -> impl Future < Output = PatriciaStorageResult < Vec < Option < DbValue > > > > + Send ;
125+ }
126+
127+ /// A trait for the storage. Extends [ReadOnlyStorage] with write operations.
128+ pub trait Storage : ReadOnlyStorage {
129+ type Stats : StorageStats ;
130+ type Config : StorageConfigTrait ;
131+
132+ /// Sets value in storage. If key already exists, its value is overwritten.
133+ // Use explicit desugaring of `async fn` to allow adding trait bounds to the return type, see
134+ // https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html#async-fn-in-public-traits
135+ // for details.
136+ fn set (
137+ & mut self ,
138+ key : DbKey ,
139+ value : DbValue ,
140+ ) -> impl Future < Output = PatriciaStorageResult < ( ) > > + Send ;
137141
138142 /// Sets values in storage.
139143 // Use explicit desugaring of `async fn` to allow adding trait bounds to the return type, see
@@ -198,21 +202,23 @@ impl StorageConfigTrait for EmptyStorageConfig {}
198202#[ derive( Clone ) ]
199203pub struct NullStorage ;
200204
201- impl Storage for NullStorage {
202- type Stats = NoStats ;
203- type Config = EmptyStorageConfig ;
204-
205+ impl ReadOnlyStorage for NullStorage {
205206 async fn get ( & mut self , _key : & DbKey ) -> PatriciaStorageResult < Option < DbValue > > {
206207 Ok ( None )
207208 }
208209
209- async fn set ( & mut self , _key : DbKey , _value : DbValue ) -> PatriciaStorageResult < ( ) > {
210- Ok ( ( ) )
211- }
212-
213210 async fn mget ( & mut self , keys : & [ & DbKey ] ) -> PatriciaStorageResult < Vec < Option < DbValue > > > {
214211 Ok ( vec ! [ None ; keys. len( ) ] )
215212 }
213+ }
214+
215+ impl Storage for NullStorage {
216+ type Stats = NoStats ;
217+ type Config = EmptyStorageConfig ;
218+
219+ async fn set ( & mut self , _key : DbKey , _value : DbValue ) -> PatriciaStorageResult < ( ) > {
220+ Ok ( ( ) )
221+ }
216222
217223 async fn mset ( & mut self , _key_to_value : DbHashMap ) -> PatriciaStorageResult < ( ) > {
218224 Ok ( ( ) )
0 commit comments