1use std::{future::Future, pin::Pin};
2
3use iroh_db_core::BlobHash;
4
5pub type BlobFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T, BlobStoreError>> + Send + 'a>>;
7
8pub trait BlobStore: Send + Sync + 'static {
10 fn put(&self, bytes: Vec<u8>) -> BlobFuture<'_, BlobHash>;
12
13 fn get(&self, hash: BlobHash) -> BlobFuture<'_, Option<Vec<u8>>>;
15
16 fn list(&self) -> BlobFuture<'_, Vec<BlobHash>>;
18
19 fn claim(&self, _hash: BlobHash) -> BlobFuture<'_, ()> {
23 Box::pin(async { Ok(()) })
24 }
25}
26
27#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
29#[error("blob store operation failed: {message}")]
30pub struct BlobStoreError {
31 message: String,
32}
33
34impl BlobStoreError {
35 pub fn new(message: impl Into<String>) -> Self {
37 Self {
38 message: message.into(),
39 }
40 }
41}