Skip to main content

backbone_bucket/domain/entity/
storage_backend.rs

1use serde::{Deserialize, Serialize};
2use sqlx::Type;
3use std::str::FromStr;
4#[cfg(feature = "openapi")]
5use utoipa::ToSchema;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Type)]
8#[cfg_attr(feature = "openapi", derive(ToSchema))]
9#[serde(rename_all = "snake_case")]
10#[sqlx(type_name = "storage_backend", rename_all = "snake_case")]
11pub enum StorageBackend {
12    Local,
13    S3,
14    Minio,
15    Gcs,
16}
17
18impl std::fmt::Display for StorageBackend {
19    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20        match self {
21            Self::Local => write!(f, "local"),
22            Self::S3 => write!(f, "s3"),
23            Self::Minio => write!(f, "minio"),
24            Self::Gcs => write!(f, "gcs"),
25        }
26    }
27}
28
29impl FromStr for StorageBackend {
30    type Err = String;
31
32    fn from_str(s: &str) -> Result<Self, Self::Err> {
33        match s.to_lowercase().as_str() {
34            "local" => Ok(Self::Local),
35            "s3" => Ok(Self::S3),
36            "minio" => Ok(Self::Minio),
37            "gcs" => Ok(Self::Gcs),
38            _ => Err(format!("Unknown StorageBackend variant: {}", s)),
39        }
40    }
41}
42
43impl Default for StorageBackend {
44    fn default() -> Self {
45        Self::Local
46    }
47}