soph_storage/support/drivers/
mod.rs

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