Skip to main content

backbone_integrations/domain/entity/
connector_direction.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 = "connector_direction", rename_all = "snake_case")]
11pub enum ConnectorDirection {
12    Inbound,
13    Outbound,
14    Both,
15}
16
17impl std::fmt::Display for ConnectorDirection {
18    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19        match self {
20            Self::Inbound => write!(f, "inbound"),
21            Self::Outbound => write!(f, "outbound"),
22            Self::Both => write!(f, "both"),
23        }
24    }
25}
26
27impl FromStr for ConnectorDirection {
28    type Err = String;
29
30    fn from_str(s: &str) -> Result<Self, Self::Err> {
31        match s.to_lowercase().as_str() {
32            "inbound" => Ok(Self::Inbound),
33            "outbound" => Ok(Self::Outbound),
34            "both" => Ok(Self::Both),
35            _ => Err(format!("Unknown ConnectorDirection variant: {}", s)),
36        }
37    }
38}
39
40impl Default for ConnectorDirection {
41    fn default() -> Self {
42        Self::Inbound
43    }
44}