ayun_storage/support/
storage.rs1use crate::{config, support::drivers, traits, Storage, StorageResult};
2
3impl Storage {
4 pub fn new(store: Box<dyn traits::StoreDriver>, config: config::Storage) -> Self {
5 Self { store, config }
6 }
7
8 pub fn try_from_config(config: config::Storage) -> StorageResult<Self> {
9 let driver = match config.driver {
10 config::Driver::Null => drivers::null::new(),
11 config::Driver::Local => drivers::local::new(),
12 config::Driver::Memory => drivers::mem::new(),
13 };
14
15 Ok(Self::new(driver, config))
16 }
17
18 pub fn config(self) -> config::Storage {
19 self.config
20 }
21}
22
23impl std::ops::Deref for Storage {
24 type Target = Box<dyn traits::StoreDriver>;
25
26 fn deref(&self) -> &Self::Target {
27 &self.store
28 }
29}