diff options
author | Joris | 2021-01-03 13:40:40 +0100 |
---|---|---|
committer | Joris | 2021-01-03 13:54:20 +0100 |
commit | 11052951b74b9ad4b6a9412ae490086235f9154b (patch) | |
tree | 64526ac926c1bf470ea113f6cac8a33158684e8d /src/model/frequency.rs | |
parent | 371449b0e312a03162b78797b83dee9d81706669 (diff) |
Rewrite in Rust
Diffstat (limited to 'src/model/frequency.rs')
-rw-r--r-- | src/model/frequency.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/model/frequency.rs b/src/model/frequency.rs new file mode 100644 index 0000000..bb83e27 --- /dev/null +++ b/src/model/frequency.rs @@ -0,0 +1,31 @@ +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<Self, Self::Err> { + match s { + "Punctual" => Ok(Frequency::Punctual), + "Monthly" => Ok(Frequency::Monthly), + _ => Err(ParseFrequencyError {}), + } + } +} |