MessageAge

Enum MessageAge 

Source
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

Source

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
Source

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());
Source

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");
Source

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);
Source

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

Source§

fn clone(&self) -> MessageAge

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MessageAge

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for MessageAge

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for MessageAge

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for MessageAge

Source§

fn eq(&self, other: &MessageAge) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&str> for MessageAge

Source§

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());
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

impl Eq for MessageAge

Source§

impl StructuralPartialEq for MessageAge

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,