ayun_storage/support/drivers/
mod.rs1use crate::{traits::StoreDriver, GetResponse, PutResponse, StorageResult};
2use async_trait::async_trait;
3use bytes::Bytes;
4use std::path::Path;
5
6pub mod local;
7pub mod mem;
8pub mod null;
9
10pub struct Adapter {
11 inner: Box<dyn object_store::ObjectStore>,
12}
13
14impl Adapter {
15 pub fn new(inner: Box<dyn object_store::ObjectStore>) -> Self {
16 Self { inner }
17 }
18}
19
20#[async_trait]
21impl StoreDriver for Adapter {
22 async fn put(&self, path: &Path, content: &Bytes) -> StorageResult<PutResponse> {
23 let path = object_store::path::Path::from(path.display().to_string());
24 let result = self.inner.put(&path, content.clone().into()).await?;
25
26 Ok(PutResponse {
27 e_tag: result.e_tag,
28 version: result.version,
29 })
30 }
31
32 async fn get(&self, path: &Path) -> StorageResult<GetResponse> {
33 let path = object_store::path::Path::from(path.display().to_string());
34
35 Ok(self.inner.get(&path).await?)
36 }
37
38 async fn delete(&self, path: &Path) -> StorageResult<()> {
39 let path = object_store::path::Path::from(path.display().to_string());
40
41 Ok(self.inner.delete(&path).await?)
42 }
43
44 async fn rename(&self, from: &Path, to: &Path) -> StorageResult<()> {
45 let from = object_store::path::Path::from(from.display().to_string());
46 let to = object_store::path::Path::from(to.display().to_string());
47
48 Ok(self.inner.rename(&from, &to).await?)
49 }
50
51 async fn copy(&self, from: &Path, to: &Path) -> StorageResult<()> {
52 let from = object_store::path::Path::from(from.display().to_string());
53 let to = object_store::path::Path::from(to.display().to_string());
54
55 Ok(self.inner.copy(&from, &to).await?)
56 }
57
58 async fn exists(&self, path: &Path) -> StorageResult<bool> {
59 let path = object_store::path::Path::from(path.display().to_string());
60
61 Ok(self.inner.get(&path).await.is_ok())
62 }
63}