use std::future::Future;
use std::pin::Pin;
use bytes::Bytes;
use futures_util::Stream;
use crate::error::ArtifactError;
pub type BlobFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T, ArtifactError>> + Send + 'a>>;
pub type ByteStream = Pin<Box<dyn Stream<Item = Result<Bytes, ArtifactError>> + Send>>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BlobDigest {
pub size_bytes: u64,
pub sha256: String,
}
pub trait BlobStore: Send + Sync {
fn put<'a>(&'a self, key: &'a str, content: ByteStream) -> BlobFuture<'a, BlobDigest>;
fn get<'a>(&'a self, key: &'a str) -> BlobFuture<'a, ByteStream>;
fn delete<'a>(&'a self, key: &'a str) -> BlobFuture<'a, bool>;
fn list_keys<'a>(&'a self, prefix: &'a str) -> BlobFuture<'a, Vec<String>>;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn blob_digest_compares_by_value() {
let a = BlobDigest {
size_bytes: 1,
sha256: "ab".to_string(),
};
let b = a.clone();
assert_eq!(a, b);
}
#[test]
fn blob_digest_differs_on_hash() {
let a = BlobDigest {
size_bytes: 1,
sha256: "ab".to_string(),
};
let b = BlobDigest {
size_bytes: 1,
sha256: "cd".to_string(),
};
assert_ne!(a, b);
}
}