pub enum MessageAge {
Days(i64),
Weeks(i64),
Months(i64),
Years(i64),
}Expand description
Message age specification for retention policies.
Defines different time periods that can be used to specify how old messages should be before they are subject to retention actions (trash/delete).
§Examples
use cull_gmail::MessageAge;
// Create different message age specifications
let days = MessageAge::Days(30);
let weeks = MessageAge::Weeks(4);
let months = MessageAge::Months(6);
let years = MessageAge::Years(2);
// Use with retention policy
println!("Messages older than {} will be processed", months);Variants§
Days(i64)
Number of days to retain the message
§Example
use cull_gmail::MessageAge;
let age = MessageAge::Days(30);
assert_eq!(age.to_string(), "d:30");Weeks(i64)
Number of weeks to retain the message
§Example
use cull_gmail::MessageAge;
let age = MessageAge::Weeks(4);
assert_eq!(age.to_string(), "w:4");Months(i64)
Number of months to retain the message
§Example
use cull_gmail::MessageAge;
let age = MessageAge::Months(6);
assert_eq!(age.to_string(), "m:6");Years(i64)
Number of years to retain the message
§Example
use cull_gmail::MessageAge;
let age = MessageAge::Years(2);
assert_eq!(age.to_string(), "y:2");Implementations§
Source§impl MessageAge
impl MessageAge
Sourcepub fn new(period: &str, count: i64) -> Result<Self>
pub fn new(period: &str, count: i64) -> Result<Self>
Create a new MessageAge from a period string and count.
§Arguments
period- The time period (“days”, “weeks”, “months”, “years”)count- The number of time periods (must be positive)
§Examples
use cull_gmail::MessageAge;
let age = MessageAge::new("days", 30).unwrap();
assert_eq!(age, MessageAge::Days(30));
let age = MessageAge::new("months", 6).unwrap();
assert_eq!(age, MessageAge::Months(6));
// Invalid period returns an error
assert!(MessageAge::new("invalid", 1).is_err());
// Negative count returns an error
assert!(MessageAge::new("days", -1).is_err());§Errors
Returns an error if:
- The period string is not recognized
- The count is negative or zero
Sourcepub fn parse(s: &str) -> Option<MessageAge>
pub fn parse(s: &str) -> Option<MessageAge>
Parse a MessageAge from a string representation (e.g., “d:30”, “m:6”).
§Arguments
s- String in format “period:count” where period is d/w/m/y
§Examples
use cull_gmail::MessageAge;
let age = MessageAge::parse("d:30").unwrap();
assert_eq!(age, MessageAge::Days(30));
let age = MessageAge::parse("y:2").unwrap();
assert_eq!(age, MessageAge::Years(2));
// Invalid format returns None
assert!(MessageAge::parse("invalid").is_none());
assert!(MessageAge::parse("d").is_none());Sourcepub fn label(&self) -> String
pub fn label(&self) -> String
Generate a label string for this message age.
This creates a standardized label that can be used to categorize messages based on their retention period.
§Examples
use cull_gmail::MessageAge;
let age = MessageAge::Days(30);
assert_eq!(age.label(), "retention/30-days");
let age = MessageAge::Years(1);
assert_eq!(age.label(), "retention/1-years");Sourcepub fn value(&self) -> i64
pub fn value(&self) -> i64
Get the numeric value of this message age.
§Examples
use cull_gmail::MessageAge;
let age = MessageAge::Days(30);
assert_eq!(age.value(), 30);
let age = MessageAge::Years(2);
assert_eq!(age.value(), 2);Sourcepub fn period_type(&self) -> &'static str
pub fn period_type(&self) -> &'static str
Get the period type as a string.
§Examples
use cull_gmail::MessageAge;
let age = MessageAge::Days(30);
assert_eq!(age.period_type(), "days");
let age = MessageAge::Years(2);
assert_eq!(age.period_type(), "years");Trait Implementations§
Source§impl Clone for MessageAge
impl Clone for MessageAge
Source§fn clone(&self) -> MessageAge
fn clone(&self) -> MessageAge
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MessageAge
impl Debug for MessageAge
Source§impl Display for MessageAge
impl Display for MessageAge
Source§impl Hash for MessageAge
impl Hash for MessageAge
Source§impl PartialEq for MessageAge
impl PartialEq for MessageAge
Source§impl TryFrom<&str> for MessageAge
impl TryFrom<&str> for MessageAge
Source§fn try_from(value: &str) -> Result<Self>
fn try_from(value: &str) -> Result<Self>
Try to create a MessageAge from a string using the parse format.
§Examples
use cull_gmail::MessageAge;
use std::convert::TryFrom;
let age = MessageAge::try_from("d:30").unwrap();
assert_eq!(age, MessageAge::Days(30));
let age = MessageAge::try_from("invalid");
assert!(age.is_err());impl Eq for MessageAge
impl StructuralPartialEq for MessageAge
Auto Trait Implementations§
impl Freeze for MessageAge
impl RefUnwindSafe for MessageAge
impl Send for MessageAge
impl Sync for MessageAge
impl Unpin for MessageAge
impl UnwindSafe for MessageAge
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more