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