Skip to content

Commit 630e3c7

Browse files
starknet_patricia_storage: implement clone for cached storage
1 parent 8cf9c0f commit 630e3c7

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

crates/starknet_patricia_storage/src/map_storage.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,25 @@ impl<S: Storage> Storage for CachedStorage<S> {
297297
}
298298

299299
fn get_async_self(&self) -> Option<impl AsyncStorage> {
300-
// Need a concrete Option type.
301-
None::<NullStorage>
300+
let underlying_storage = self.storage.get_async_self()?;
301+
Some(CachedStorage {
302+
storage: underlying_storage,
303+
cache: self.cache.clone(), // This clone is cheap.
304+
cache_on_write: self.cache_on_write,
305+
writes: self.writes,
306+
include_inner_stats: self.include_inner_stats,
307+
})
308+
}
309+
}
310+
311+
impl<S: AsyncStorage> Clone for CachedStorage<S> {
312+
fn clone(&self) -> Self {
313+
Self {
314+
storage: self.storage.clone(),
315+
cache: self.cache.clone(), // This clone is cheap.
316+
cache_on_write: self.cache_on_write,
317+
writes: self.writes,
318+
include_inner_stats: self.include_inner_stats,
319+
}
302320
}
303321
}

0 commit comments

Comments
 (0)