use std::time::Duration;
use async_trait::async_trait;
use bytes::Bytes;
use crate::error::Result;
use crate::types::{ListOutcome, ObjectMetadata, PutBody, PutOptions};
#[derive(Debug, Clone, Default)]
pub struct ListOptions {
pub marker: Option<String>,
pub limit: Option<u32>,
pub delimiter: Option<String>,
}
impl ListOptions {
pub fn with_limit(limit: u32) -> Self {
ListOptions {
limit: Some(limit),
..Default::default()
}
}
}
#[async_trait]
pub trait ObjectStorage: Send + Sync {
fn backend(&self) -> &'static str;
fn bucket(&self) -> &str;
async fn put(&self, key: &str, body: PutBody, opts: &PutOptions) -> Result<ObjectMetadata>;
async fn put_resumable(
&self,
key: &str,
body: PutBody,
part_size: usize,
opts: &PutOptions,
) -> Result<ObjectMetadata> {
let _ = part_size;
self.put(key, body, opts).await
}
async fn get(&self, key: &str) -> Result<Bytes>;
async fn delete(&self, key: &str) -> Result<()>;
async fn exists(&self, key: &str) -> Result<bool>;
async fn stat(&self, key: &str) -> Result<ObjectMetadata>;
async fn list(&self, prefix: &str, opts: &ListOptions) -> Result<ListOutcome>;
fn presign_get(&self, key: &str, expires: Duration) -> Result<String>;
}