ayun_storage/drivers/
mod.rsuse crate::traits::{GetResponse, PutResponse, StorageResult, StoreDriver};
use async_trait::async_trait;
use bytes::Bytes;
use std::path::Path;
pub mod local;
pub mod mem;
pub mod null;
pub struct Adapter {
inner: Box<dyn object_store::ObjectStore>,
}
impl Adapter {
pub fn new(inner: Box<dyn object_store::ObjectStore>) -> Self {
Self { inner }
}
}
#[async_trait]
impl StoreDriver for Adapter {
async fn put(&self, path: &Path, content: &Bytes) -> StorageResult<PutResponse> {
let path = object_store::path::Path::from(path.display().to_string());
let result = self.inner.put(&path, content.clone().into()).await?;
Ok(PutResponse {
e_tag: result.e_tag,
version: result.version,
})
}
async fn get(&self, path: &Path) -> StorageResult<GetResponse> {
let path = object_store::path::Path::from(path.display().to_string());
Ok(self.inner.get(&path).await?)
}
async fn delete(&self, path: &Path) -> StorageResult<()> {
let path = object_store::path::Path::from(path.display().to_string());
Ok(self.inner.delete(&path).await?)
}
async fn rename(&self, from: &Path, to: &Path) -> StorageResult<()> {
let from = object_store::path::Path::from(from.display().to_string());
let to = object_store::path::Path::from(to.display().to_string());
Ok(self.inner.rename(&from, &to).await?)
}
async fn copy(&self, from: &Path, to: &Path) -> StorageResult<()> {
let from = object_store::path::Path::from(from.display().to_string());
let to = object_store::path::Path::from(to.display().to_string());
Ok(self.inner.copy(&from, &to).await?)
}
async fn exists(&self, path: &Path) -> StorageResult<bool> {
let path = object_store::path::Path::from(path.display().to_string());
Ok(self.inner.get(&path).await.is_ok())
}
}