Skip to main content

AppConfig

Struct AppConfig 

Source
pub struct AppConfig {
    pub providers: HashMap<String, ProviderSettings>,
}
Expand description

App configuration, persisted at ~/.config/usage-monitor/config.toml.

Fields§

§providers: HashMap<String, ProviderSettings>

Implementations§

Source§

impl AppConfig

Source

pub fn default_path() -> Option<PathBuf>

Default config path: $XDG_CONFIG_HOME/usage-monitor/config.toml or ~/.config/usage-monitor/config.toml.

Source

pub fn load_from_path(path: &Path) -> Result<Self, SpendPanelError>

Loads the config from a path. A missing file yields the default config.

Source

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

Loads the config from the default path (missing file → default config).

Source

pub fn save_to_path(&self, path: &Path) -> Result<(), SpendPanelError>

Saves the config as TOML, creating parent directories if needed.

Source

pub fn provider_enabled(&self, id: &str) -> Option<bool>

Explicit provider-level toggle, if any.

Source

pub fn set_provider_enabled(&mut self, id: &str, enabled: bool)

Sets the explicit provider-level toggle.

Source

pub fn clear_provider_enabled(&mut self, id: &str)

Clears the explicit provider toggle, returning it to auto-detection.

Source

pub fn resolve_state( &self, id: &str, credentials_detected: bool, ) -> ProviderState

Resolves the state of a provider: explicit setting wins, otherwise falls back to credential detection or the presence of configured accounts.

Source

pub fn has_accounts(&self, id: &str) -> bool

True when the provider has at least one configured account.

Source

pub fn account_ids(&self, id: &str) -> Vec<String>

Sorted account names configured for a provider (empty when none).

Source

pub fn account(&self, id: &str, account: &str) -> Option<&AccountSettings>

An account’s settings, if configured.

Source

pub fn add_account( &mut self, id: &str, account: &str, label: Option<&str>, ) -> bool

Creates an account (no-op if it already exists), returning whether it was newly created.

Source

pub fn remove_account(&mut self, id: &str, account: &str) -> bool

Removes an account entirely. Returns whether it existed.

Source

pub fn set_account_label(&mut self, id: &str, account: &str, label: &str)

Sets the account label.

Source

pub fn account_label(&self, id: &str, account: &str) -> Option<&str>

Account label, if set.

Source

pub fn set_account_config( &mut self, id: &str, account: &str, key: &str, value: &str, )

Sets a key in an account’s table. The token key maps to the typed field; everything else is stored flat.

Source

pub fn unset_account_config(&mut self, id: &str, account: &str, key: &str)

Removes a key from an account’s table, cleaning up empty entries.

Source

pub fn account_config( &self, id: &str, account: &str, ) -> Option<&HashMap<String, String>>

An account’s flat config keys (excluding typed fields), if any.

Source

pub fn account_token(&self, id: &str, account: &str) -> Option<&str>

An account’s auth token, if set.

Source

pub fn account_workspaces(&self, id: &str, account: &str) -> &[String]

An account’s workspace list (empty when unset).

Source

pub fn set_account_workspaces( &mut self, id: &str, account: &str, workspaces: Vec<String>, )

Replaces an account’s workspace list, cleaning up empty entries.

Source

pub fn account_enabled(&self, id: &str, account: &str) -> Option<bool>

Explicit per-account toggle, if any.

Source

pub fn set_account_enabled(&mut self, id: &str, account: &str, enabled: bool)

Sets the explicit per-account toggle.

Source

pub fn clear_account_enabled(&mut self, id: &str, account: &str)

Clears the explicit per-account toggle, cleaning up empty entries.

Source

pub fn account_is_enabled(&self, id: &str, account: &str) -> bool

True when the account is enabled (explicit toggle wins, else enabled).

Trait Implementations§

Source§

impl Clone for AppConfig

Source§

fn clone(&self) -> AppConfig

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 AppConfig

Source§

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

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

impl Default for AppConfig

Source§

fn default() -> AppConfig

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

impl<'de> Deserialize<'de> for AppConfig

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 PartialEq for AppConfig

Source§

fn eq(&self, other: &AppConfig) -> 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 AppConfig

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 AppConfig

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<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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. 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, 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, <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