post3 0.1.0

Pluggable S3-compatible object storage — core library with PostgreSQL and filesystem backends
Documentation
use std::collections::HashMap;
use std::future::Future;

use bytes::Bytes;

use crate::error::Post3Error;
use crate::models::{
    BucketInfo, CompleteMultipartUploadResult, CreateMultipartUploadResult, GetObjectResult,
    HeadObjectResult, ListMultipartUploadsResult, ListObjectsResult, ListPartsResult,
    PutObjectResult, UploadPartResult,
};

/// Trait abstracting storage operations. Implemented by `PostgresBackend` and `FilesystemBackend`.
pub trait StorageBackend: Clone + Send + Sync + 'static {
    // --- Bucket operations ---

    fn create_bucket(
        &self,
        name: &str,
    ) -> impl Future<Output = Result<BucketInfo, Post3Error>> + Send;

    fn head_bucket(
        &self,
        name: &str,
    ) -> impl Future<Output = Result<Option<BucketInfo>, Post3Error>> + Send;

    fn delete_bucket(
        &self,
        name: &str,
    ) -> impl Future<Output = Result<(), Post3Error>> + Send;

    fn list_buckets(&self) -> impl Future<Output = Result<Vec<BucketInfo>, Post3Error>> + Send;

    // --- Object operations ---

    fn put_object(
        &self,
        bucket: &str,
        key: &str,
        content_type: Option<&str>,
        metadata: HashMap<String, String>,
        body: Bytes,
    ) -> impl Future<Output = Result<PutObjectResult, Post3Error>> + Send;

    fn get_object(
        &self,
        bucket: &str,
        key: &str,
    ) -> impl Future<Output = Result<GetObjectResult, Post3Error>> + Send;

    fn head_object(
        &self,
        bucket: &str,
        key: &str,
    ) -> impl Future<Output = Result<Option<HeadObjectResult>, Post3Error>> + Send;

    fn delete_object(
        &self,
        bucket: &str,
        key: &str,
    ) -> impl Future<Output = Result<(), Post3Error>> + Send;

    fn list_objects_v2(
        &self,
        bucket: &str,
        prefix: Option<&str>,
        continuation_token: Option<&str>,
        max_keys: Option<i64>,
        delimiter: Option<&str>,
    ) -> impl Future<Output = Result<ListObjectsResult, Post3Error>> + Send;

    // --- Multipart upload operations ---

    fn create_multipart_upload(
        &self,
        bucket: &str,
        key: &str,
        content_type: Option<&str>,
        metadata: HashMap<String, String>,
    ) -> impl Future<Output = Result<CreateMultipartUploadResult, Post3Error>> + Send;

    fn upload_part(
        &self,
        bucket: &str,
        key: &str,
        upload_id: &str,
        part_number: i32,
        body: Bytes,
    ) -> impl Future<Output = Result<UploadPartResult, Post3Error>> + Send;

    fn complete_multipart_upload(
        &self,
        bucket: &str,
        key: &str,
        upload_id: &str,
        part_etags: Vec<(i32, String)>,
    ) -> impl Future<Output = Result<CompleteMultipartUploadResult, Post3Error>> + Send;

    fn abort_multipart_upload(
        &self,
        bucket: &str,
        key: &str,
        upload_id: &str,
    ) -> impl Future<Output = Result<(), Post3Error>> + Send;

    fn list_parts(
        &self,
        bucket: &str,
        key: &str,
        upload_id: &str,
        max_parts: Option<i32>,
        part_number_marker: Option<i32>,
    ) -> impl Future<Output = Result<ListPartsResult, Post3Error>> + Send;

    fn list_multipart_uploads(
        &self,
        bucket: &str,
        prefix: Option<&str>,
        key_marker: Option<&str>,
        upload_id_marker: Option<&str>,
        max_uploads: Option<i32>,
    ) -> impl Future<Output = Result<ListMultipartUploadsResult, Post3Error>> + Send;
}