Crates.io | storage-client-interface |
lib.rs | storage-client-interface |
version | 0.3.0 |
source | src |
created_at | 2023-08-30 12:21:13.276577 |
updated_at | 2024-10-07 16:00:58.477541 |
description | A Rust library for exposing the StorageClientInterface trait for interacting with a storage backend. Used by Evervault Cages. |
homepage | https://github.com/evervault/storage-client-interface |
repository | https://github.com/evervault/storage-client-interface |
max_upload_size | |
id | 958923 |
size | 12,023 |
The StorageClientInterface is a trait that defines a set of methods for interacting with object storage. It provides a clear and standardized way to perform common operations for retrieving, uploading, and deleting objects from a storage service. An S3 implementation is also provided under the feature s3
which is included under the default
feature.
use async_trait::async_trait;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum StorageClientError {
#[error("GetObject Error: {0}")]
GetObject(String),
#[error("PutObject Error: {0}")]
PutObject(String),
#[error("DeleteObject Error: {0}")]
DeleteObject(String),
#[error("Storage Client Error - {0}")]
General(String),
}
#[async_trait]
pub trait StorageClientInterface {
async fn get_object(&self, key: String) -> Result<Option<String>, StorageClientError>;
async fn put_object(&self, key: String, body: String) -> Result<(), StorageClientError>;
async fn delete_object(&self, key: String) -> Result<(), StorageClientError>;
}
Retrieves an object from the storage service based on the provided key.
async fn get_object(&self, key: String) -> Result<Option<String>, StorageClientError>;
Uploads an object to the storage service with the given key and body.
async fn put_object(&self, key: String, body: String) -> Result<(), StorageClientError>;
Deletes an object from the storage service using the specified key.
async fn delete_object(&self, key: String) -> Result<(), StorageClientError>;