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
impl App
pub const OPSH: Self
pub const TERMINAL: Self
pub const MUSIC: Self
pub const FILES: Self
pub const OS: Self
pub const DE: Self
pub const CAL: Self
pub const SEARCH: Self
Sourcepub fn new(
id: impl Into<Cow<'static, str>>,
mark: impl Into<Cow<'static, str>>,
display_name: impl Into<Cow<'static, str>>,
) -> Self
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.
Sourcepub fn known(id: &str) -> Option<Self>
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.
pub fn id(&self) -> &str
pub fn mark(&self) -> &str
pub fn display_name(&self) -> &str
Sourcepub fn config_toml(&self) -> PathBuf
pub fn config_toml(&self) -> PathBuf
~/.option/<dir_name>/config.toml
Sourcepub fn session_toml(&self) -> PathBuf
pub fn session_toml(&self) -> PathBuf
~/.option/<dir_name>/session.toml
Sourcepub fn path(&self, relative: impl AsRef<Path>) -> PathBuf
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.
Sourcepub fn try_path(&self, relative: impl AsRef<Path>) -> Result<PathBuf>
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.
Sourcepub fn ensure(&self) -> Result<PathBuf>
pub fn ensure(&self) -> Result<PathBuf>
Create the app directory (and ~/.option), migrating any known legacy tree.
Returns the canonical app directory path.
Sourcepub fn ensure_cache(&self) -> Result<PathBuf>
pub fn ensure_cache(&self) -> Result<PathBuf>
Ensure the app directory exists, then create cache/ under it.
Returns the cache directory path.
Sourcepub fn migrate_legacy(&self) -> Result<bool>
pub fn migrate_legacy(&self) -> Result<bool>
Migrate a known legacy home-relative tree into Self::dir when missing.
Source§impl App
impl App
Sourcepub fn load_config<T: DeserializeOwned + Serialize + Default>(
&self,
) -> Result<T, ConfigError>
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.
Sourcepub fn save_config<T: Serialize>(&self, value: &T) -> Result<(), ConfigError>
pub fn save_config<T: Serialize>(&self, value: &T) -> Result<(), ConfigError>
Persist value to config.toml (via crate::atomic_write).
Trait Implementations§
impl Eq for App
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> 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.