Skip to main content

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