use std::sync::Arc;
use libipld::Block;
use crate::libp2p_bitswap::*;
pub trait BitswapStoreRead {
fn contains(&self, cid: &Cid) -> anyhow::Result<bool>;
fn get(&self, cid: &Cid) -> anyhow::Result<Option<Vec<u8>>>;
}
pub trait BitswapStoreReadWrite: BitswapStoreRead + Send + Sync + 'static {
type Params: StoreParams;
fn insert(&self, block: &Block<Self::Params>) -> anyhow::Result<()>;
}
impl<T: BitswapStoreRead> BitswapStoreRead for Arc<T> {
fn contains(&self, cid: &Cid) -> anyhow::Result<bool> {
BitswapStoreRead::contains(self.as_ref(), cid)
}
fn get(&self, cid: &Cid) -> anyhow::Result<Option<Vec<u8>>> {
BitswapStoreRead::get(self.as_ref(), cid)
}
}
impl<T: BitswapStoreReadWrite> BitswapStoreReadWrite for Arc<T> {
type Params = <T as BitswapStoreReadWrite>::Params;
fn insert(&self, block: &libipld::Block<Self::Params>) -> anyhow::Result<()> {
BitswapStoreReadWrite::insert(self.as_ref(), block)
}
}