fuel_merkle/
storage.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use alloc::borrow::Cow;
use core::convert::Infallible;

// Re-export fuel-storage traits
pub use fuel_storage::{
    Mappable,
    StorageInspect,
    StorageMutate,
};

pub trait StorageInspectInfallible<Type: Mappable> {
    fn get(&self, key: &Type::Key) -> Option<Cow<Type::OwnedValue>>;
    fn contains_key(&self, key: &Type::Key) -> bool;
}

pub trait StorageMutateInfallible<Type: Mappable> {
    fn insert(&mut self, key: &Type::Key, value: &Type::Value);
    fn remove(&mut self, key: &Type::Key);
}

impl<S, Type> StorageInspectInfallible<Type> for S
where
    S: StorageInspect<Type, Error = Infallible>,
    Type: Mappable,
{
    fn get(&self, key: &Type::Key) -> Option<Cow<Type::OwnedValue>> {
        <Self as StorageInspect<Type>>::get(self, key)
            .expect("Expected get() to be infallible")
    }

    fn contains_key(&self, key: &Type::Key) -> bool {
        <Self as StorageInspect<Type>>::contains_key(self, key)
            .expect("Expected contains_key() to be infallible")
    }
}

impl<S, Type> StorageMutateInfallible<Type> for S
where
    S: StorageMutate<Type, Error = Infallible>,
    Type: Mappable,
{
    fn insert(&mut self, key: &Type::Key, value: &Type::Value) {
        <Self as StorageMutate<Type>>::insert(self, key, value)
            .expect("Expected insert() to be infallible")
    }

    fn remove(&mut self, key: &Type::Key) {
        <Self as StorageMutate<Type>>::remove(self, key)
            .expect("Expected remove() to be infallible")
    }
}