fuel_merkle/
storage.rs

1use alloc::borrow::Cow;
2use core::convert::Infallible;
3
4// Re-export fuel-storage traits
5pub use fuel_storage::{
6    Mappable,
7    StorageInspect,
8    StorageMutate,
9};
10
11pub trait StorageInspectInfallible<Type: Mappable> {
12    fn get(&self, key: &Type::Key) -> Option<Cow<Type::OwnedValue>>;
13    fn contains_key(&self, key: &Type::Key) -> bool;
14}
15
16pub trait StorageMutateInfallible<Type: Mappable> {
17    fn insert(&mut self, key: &Type::Key, value: &Type::Value);
18    fn remove(&mut self, key: &Type::Key);
19}
20
21impl<S, Type> StorageInspectInfallible<Type> for S
22where
23    S: StorageInspect<Type, Error = Infallible>,
24    Type: Mappable,
25{
26    fn get(&self, key: &Type::Key) -> Option<Cow<Type::OwnedValue>> {
27        <Self as StorageInspect<Type>>::get(self, key)
28            .expect("Expected get() to be infallible")
29    }
30
31    fn contains_key(&self, key: &Type::Key) -> bool {
32        <Self as StorageInspect<Type>>::contains_key(self, key)
33            .expect("Expected contains_key() to be infallible")
34    }
35}
36
37impl<S, Type> StorageMutateInfallible<Type> for S
38where
39    S: StorageMutate<Type, Error = Infallible>,
40    Type: Mappable,
41{
42    fn insert(&mut self, key: &Type::Key, value: &Type::Value) {
43        <Self as StorageMutate<Type>>::insert(self, key, value)
44            .expect("Expected insert() to be infallible")
45    }
46
47    fn remove(&mut self, key: &Type::Key) {
48        <Self as StorageMutate<Type>>::remove(self, key)
49            .expect("Expected remove() to be infallible")
50    }
51}