mod memory;
#[cfg(feature = "s3")]
mod s3;
pub use memory::MemoryBackend;
#[cfg(feature = "s3")]
pub use s3::{S3Backend, S3BackendBuilder};
use async_trait::async_trait;
use bytes::Bytes;
use futures::stream::BoxStream;
use crate::error::Result;
pub type BackendReader<'a> = BoxStream<'a, std::result::Result<Bytes, std::io::Error>>;
pub type BackendBody = Box<dyn tokio::io::AsyncRead + Send + Unpin>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct BackendMetadata {
pub content_length: Option<u64>,
pub etag: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ListedObject {
pub key: String,
pub size: u64,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ListPage {
pub objects: Vec<ListedObject>,
pub continuation_token: Option<String>,
}
#[async_trait]
pub trait ObjectBackend: Send + Sync {
async fn put(&self, key: &str, body: BackendReader<'_>) -> Result<u64>;
async fn get(&self, key: &str) -> Result<BackendBody>;
async fn delete(&self, key: &str) -> Result<()>;
async fn head(&self, key: &str) -> Result<BackendMetadata>;
async fn list(&self, prefix: &str, continuation_token: Option<&str>) -> Result<ListPage>;
}