Skip to main content

App

Struct App 

Source
pub struct App { /* private fields */ }
Expand description

An Option family application.

Known apps are available as associated constants (App::OPSH, …). Custom / experimental apps use App::new, which also accepts owned String ids (e.g. from config or CLI).

App is Clone but not Copy (identity strings are Cow<'static, str> so dynamic ids work without leaking).

Implementations§

Source§

impl App

Source

pub const OPSH: Self

Source

pub const TERMINAL: Self

Source

pub const MUSIC: Self

Source

pub const FILES: Self

Source

pub const OS: Self

Source

pub const DE: Self

Source

pub const CAL: Self

Source

pub const SEARCH: Self

Source

pub const ALL: &'static [Self]

All known family apps.

Source

pub fn new( id: impl Into<Cow<'static, str>>, mark: impl Into<Cow<'static, str>>, display_name: impl Into<Cow<'static, str>>, ) -> Self

Build a custom app identity (no built-in legacy migrate).

Accepts &'static str or owned String (e.g. from config/CLI). dir_name is set to id.

Source

pub fn known(id: &str) -> Option<Self>

Look up a known app by id ("music", "opsh", …). "needle" resolves to SEARCH as a legacy alias of the rename.

Source

pub fn id(&self) -> &str

Source

pub fn mark(&self) -> &str

Source

pub fn display_name(&self) -> &str

Source

pub fn bundle_id(&self) -> String

Reverse-DNS bundle id, e.g. io.option.music.

Source

pub fn dir(&self) -> PathBuf

~/.option/<dir_name>

Source

pub fn config_toml(&self) -> PathBuf

~/.option/<dir_name>/config.toml

Source

pub fn cache_dir(&self) -> PathBuf

~/.option/<dir_name>/cache

Source

pub fn keys_toml(&self) -> PathBuf

~/.option/<dir_name>/keys.toml

Source

pub fn session_toml(&self) -> PathBuf

~/.option/<dir_name>/session.toml

Source

pub fn path(&self, relative: impl AsRef<Path>) -> PathBuf

Join a relative path under the app directory.

The caller must pass a relative path with no .. components. For untrusted input use Self::try_path, which enforces this containment contract and returns an error instead of joining.

Source

pub fn try_path(&self, relative: impl AsRef<Path>) -> Result<PathBuf>

Checked variant of Self::path for untrusted input.

Rejects absolute paths and any .. component so the result stays under the app directory. Internal callers (keys_toml, session_toml) route through here with static names.

Source

pub fn ensure(&self) -> Result<PathBuf>

Create the app directory (and ~/.option), migrating any known legacy tree.

Returns the canonical app directory path.

Source

pub fn ensure_cache(&self) -> Result<PathBuf>

Ensure the app directory exists, then create cache/ under it.

Returns the cache directory path.

Source

pub fn migrate_legacy(&self) -> Result<bool>

Migrate a known legacy home-relative tree into Self::dir when missing.

Source§

impl App

Source

pub fn load_config<T: DeserializeOwned + Serialize + Default>( &self, ) -> Result<T, ConfigError>

Load config.toml, writing T::default() when the file is missing.

Runs App::ensure first, so the app directory and legacy migration are handled before the file is touched.

Source

pub fn save_config<T: Serialize>(&self, value: &T) -> Result<(), ConfigError>

Persist value to config.toml (via crate::atomic_write).

Trait Implementations§

Source§

impl Clone for App

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 App

Source§

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

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

impl Eq for App

Source§

impl Hash for App

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 App

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 StructuralPartialEq for App

Auto Trait Implementations§

§

impl Forget for App

§

impl Freeze for App

§

impl Move for App

§

impl RefUnwindSafe for App

§

impl Send for App

§

impl Sync for App

§

impl Unpin for App

§

impl UnsafeUnpin for App

§

impl UnwindSafe for App

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, 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> 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.