use serde::{Deserialize, Serialize}; use std::{fmt, str}; #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, sqlx::Type)] pub enum Frequency { Punctual, Monthly, } impl fmt::Display for Frequency { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Frequency::Punctual => write!(f, "Punctual"), Frequency::Monthly => write!(f, "Monthly"), } } } pub struct ParseFrequencyError; impl str::FromStr for Frequency { type Err = ParseFrequencyError; fn from_str(s: &str) -> Result { match s { "Punctual" => Ok(Frequency::Punctual), "Monthly" => Ok(Frequency::Monthly), _ => Err(ParseFrequencyError {}), } } }