Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub accounts: Vec<Account>,
    pub defaults: Defaults,
    pub trusted_senders: Vec<String>,
    pub classify: ClassifyConfig,
    pub guardrails: BTreeMap<String, String>,
}

Fields§

§accounts: Vec<Account>§defaults: Defaults§trusted_senders: Vec<String>§classify: ClassifyConfig§guardrails: BTreeMap<String, String>

Guardrails: action class -> “allow” | “confirm” | “deny”. Classes: send, delete, cancel, rsvp, bulk, unsubscribe.

Implementations§

Source§

impl Config

Source

pub const GUARDRAIL_CLASSES: [&'static str; 6]

Valid guardrail action classes.

Source

pub const KNOWN_KEYS: &'static [&'static str]

Every settable config key, for pidge config show/help.

Source

pub fn default_path() -> Result<PathBuf, CoreError>

Default path: ${XDG_CONFIG_HOME:-~/.config}/pidge/config.yaml.

Source

pub fn load() -> Result<Self, CoreError>

Load the config from the default path. If the file doesn’t exist, returns Config::default().

Source

pub fn load_from(path: &Path) -> Result<Self, CoreError>

Load from a specific path. Useful for tests.

Source

pub fn save(&self) -> Result<(), CoreError>

Save the config to the default path.

Source

pub fn save_to(&self, path: &Path) -> Result<(), CoreError>

Save to a specific path. Useful for tests.

Source

pub fn add_account(&mut self, account: Account)

Add or replace an account by email. If this is the first account, also sets it as the default send AND default calendar account.

Source

pub fn remove_account(&mut self, email: &str) -> Option<Account>

Remove an account by email. Returns the removed account. If the removed account was a default, that default is cleared.

Source

pub fn set_default_send(&mut self, email: &str) -> Result<(), CoreError>

Set the default send account. Errors if the email isn’t a known signed-in account.

Source

pub fn set_default_calendar(&mut self, email: &str) -> Result<(), CoreError>

Set the default calendar account. Errors if the email isn’t a known signed-in account.

Source

pub fn find(&self, email: &str) -> Option<&Account>

Find an account by email.

Source

pub fn add_trusted_sender(&mut self, email: &str)

Add an email to the trusted-senders list (case-insensitive). Idempotent.

Source

pub fn remove_trusted_sender(&mut self, email: &str) -> bool

Remove an email from the trusted-senders list (case-insensitive). Returns true if it was present, false if it wasn’t (idempotent either way).

Source

pub fn is_sender_trusted(&self, email: &str) -> bool

Case-insensitive check for whether an email is in the trusted-senders list.

Source

pub fn get_key(&self, key: &str) -> Option<String>

Read a dotted config key as a display string, or None if unset.

Source

pub fn set_key(&mut self, key: &str, value: &str) -> Result<(), CoreError>

Set a dotted config key from a string value. Errors on unknown key or unparseable value.

Source

pub fn unset_key(&mut self, key: &str) -> Result<(), CoreError>

Revert a dotted config key to its unset/default state.

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

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

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

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config
where Config: Default,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Config

Source§

impl PartialEq for Config

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Config

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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, 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> Same for T

Source§

type Output = T

Should always be Self
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.