fuel_streams_storage/
storage.rs1use async_trait::async_trait;
2use displaydoc::Display as DisplayDoc;
3use thiserror::Error;
4
5use crate::StorageConfig;
6
7#[derive(Error, Debug, DisplayDoc)]
8pub enum StorageError {
9 StoreError(String),
11 RetrieveError(String),
13 DeleteError(String),
15 InitError(String),
17}
18
19#[async_trait]
20pub trait Storage: std::fmt::Debug + Send + Sync {
21 type Config: StorageConfig;
22
23 async fn new(config: Self::Config) -> Result<Self, StorageError>
24 where
25 Self: Sized;
26
27 async fn new_admin() -> Result<Self, StorageError>
28 where
29 Self: Sized,
30 {
31 Self::new(Self::Config::admin_opts()).await
32 }
33
34 async fn new_public() -> Result<Self, StorageError>
35 where
36 Self: Sized,
37 {
38 Self::new(Self::Config::public_opts()).await
39 }
40
41 async fn store(&self, key: &str, data: Vec<u8>)
42 -> Result<(), StorageError>;
43
44 async fn retrieve(&self, key: &str) -> Result<Vec<u8>, StorageError>;
45
46 async fn delete(&self, key: &str) -> Result<(), StorageError>;
47}