noosphere_storage/
storage.rs

1use crate::block::BlockStore;
2use crate::key_value::KeyValueStore;
3use anyhow::Result;
4use async_trait::async_trait;
5use noosphere_common::ConditionalSync;
6use std::fmt::Debug;
7
8/// [Storage] is a general trait for composite storage backends. It is often the
9/// case that we are able to use a single storage primitive for all forms of
10/// storage, but sometimes block storage and generic key/value storage come from
11/// different backends. [Storage] provides a composite interface where both
12/// cases well accomodated without creating complexity in the signatures of
13/// other Noosphere constructs.
14#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
15#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
16pub trait Storage: Clone + ConditionalSync + Debug {
17    type BlockStore: BlockStore;
18    type KeyValueStore: KeyValueStore;
19
20    /// Get a [BlockStore] where all values stored in it are scoped to the given
21    /// name
22    async fn get_block_store(&self, name: &str) -> Result<Self::BlockStore>;
23
24    /// Get a [KeyValueStore] where all values stored in it are scoped to the
25    /// given name
26    async fn get_key_value_store(&self, name: &str) -> Result<Self::KeyValueStore>;
27}