pub struct AppPaths { /* private fields */ }Expand description
Resolved OS-correct application directories (config and data).
Construct with AppPaths::new for production code, or
AppPaths::for_testing in tests and headless CI environments.
Use AppPaths::from_dirs when the application manages its own
directory layout (e.g. portable mode).
Implementations§
Source§impl AppPaths
impl AppPaths
Sourcepub fn new(
qualifier: &str,
organization: &str,
application: &str,
) -> Option<Self>
pub fn new( qualifier: &str, organization: &str, application: &str, ) -> Option<Self>
Resolve directories from the OS. The (qualifier, organization, application) triple feeds [etcetera::AppStrategyArgs] as
(top_level_domain, author, app_name) — same fields, different
names — and selects the platform-native strategy (XDG on Linux,
%APPDATA%-based on Windows, ~/Library/Application Support
on macOS).
Returns None when no usable home directory could be detected
(a sandboxed or unconfigured environment). Callers who want to
degrade gracefully should fall back to AppPaths::for_testing
with an in-process directory.
Sourcepub fn for_testing(root: &Path) -> Self
pub fn for_testing(root: &Path) -> Self
Construct an AppPaths rooted at an arbitrary directory. Used by
tests so that no test ever touches the user’s real config tree.
Both config_dir and data_dir resolve to root.
Sourcepub fn from_dirs(config_dir: PathBuf, data_dir: PathBuf) -> Self
pub fn from_dirs(config_dir: PathBuf, data_dir: PathBuf) -> Self
Construct from explicit config and data directories. Useful when an application wants to override one or both (e.g. portable mode).
Sourcepub fn config_dir(&self) -> &Path
pub fn config_dir(&self) -> &Path
The platform-correct config directory (XDG_CONFIG_HOME, %APPDATA%,
~/Library/Preferences, etc.).
Sourcepub fn data_dir(&self) -> &Path
pub fn data_dir(&self) -> &Path
The platform-correct data directory. Used for caches and per-window state — anything larger than a configuration file.
Sourcepub fn config_file(&self, name: &str) -> PathBuf
pub fn config_file(&self, name: &str) -> PathBuf
Resolve a per-concern config file by name (without extension).
name = "general" yields <config_dir>/general.toml.