use std::{fmt, str::FromStr}; use serde::{Deserialize, Serialize}; #[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] #[serde(rename_all = "lowercase")] pub enum ClassificationAction { Reply, Review, Archive, Delete, } impl ClassificationAction { pub fn is_mailbox_action(self) -> bool { matches!(self, Self::Archive | Self::Delete) } } impl fmt::Display for ClassificationAction { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str(match self { Self::Reply => "reply", Self::Review => "review", Self::Archive => "archive", Self::Delete => "delete", }) } } impl FromStr for ClassificationAction { type Err = String; fn from_str(value: &str) -> Result { match value { "reply" => Ok(Self::Reply), "review" => Ok(Self::Review), "archive" => Ok(Self::Archive), "delete" => Ok(Self::Delete), _ => Err(format!("unknown classification action: {value}")), } } }