Files
cull-gmail/src/eol_action.rs
Jeremiah Russell 9c237d8681 feat(eol_action): add parse method to EolAction
- implement `parse` method for `EolAction` to convert strings to `EolAction` variants
- support "trash" and "delete" strings, return `None` for others
2025-10-11 09:35:12 +01:00

34 lines
941 B
Rust

use std::fmt;
/// End of life action
/// - Trash - move the message to the trash to be automatically deleted by Google
/// - Delete - delete the message immediately without allowing rescue from trash
#[derive(Debug, Default)]
pub enum EolAction {
#[default]
/// Move the message to the trash
Trash,
/// Delete the message immediately
Delete,
}
impl fmt::Display for EolAction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EolAction::Trash => write!(f, "trash"),
EolAction::Delete => write!(f, "delete"),
}
}
}
impl EolAction {
/// Parse a string to a valid `EolAction` variant or return `None`.
pub fn parse(str: &str) -> Option<EolAction> {
match str.to_lowercase().as_str() {
"trash" => Some(EolAction::Trash),
"delete" => Some(EolAction::Delete),
_ => None,
}
}
}