pub struct AppPaths { /* private fields */ }Expand description
Application path manager with configurable resolution strategies.
Provides platform-agnostic path resolution for configuration and data directories.
§Example
use version_migrate::{AppPaths, PathStrategy};
// Use OS-standard directories (default)
let paths = AppPaths::new("myapp");
let config_path = paths.config_file("config.toml")?;
// Force XDG on all platforms
let paths = AppPaths::new("myapp")
.config_strategy(PathStrategy::Xdg);
let config_path = paths.config_file("config.toml")?;
// Use custom base directory
let paths = AppPaths::new("myapp")
.config_strategy(PathStrategy::CustomBase("/opt/myapp".into()));Implementations§
Source§impl AppPaths
impl AppPaths
Sourcepub fn config_strategy(self, strategy: PathStrategy) -> Self
pub fn config_strategy(self, strategy: PathStrategy) -> Self
Sourcepub fn data_strategy(self, strategy: PathStrategy) -> Self
pub fn data_strategy(self, strategy: PathStrategy) -> Self
Sourcepub fn config_dir(&self) -> Result<PathBuf, MigrationError>
pub fn config_dir(&self) -> Result<PathBuf, MigrationError>
Get the configuration directory path.
Creates the directory if it doesn’t exist.
§Returns
The resolved configuration directory path.
§Errors
Returns MigrationError::HomeDirNotFound if the home directory cannot be determined.
Returns MigrationError::IoError if directory creation fails.
§Example
let config_dir = paths.config_dir()?;
// On Linux with System strategy: ~/.config/myapp
// On macOS with System strategy: ~/Library/Application Support/myappSourcepub fn data_dir(&self) -> Result<PathBuf, MigrationError>
pub fn data_dir(&self) -> Result<PathBuf, MigrationError>
Get the data directory path.
Creates the directory if it doesn’t exist.
§Returns
The resolved data directory path.
§Errors
Returns MigrationError::HomeDirNotFound if the home directory cannot be determined.
Returns MigrationError::IoError if directory creation fails.
§Example
let data_dir = paths.data_dir()?;
// On Linux with System strategy: ~/.local/share/myapp
// On macOS with System strategy: ~/Library/Application Support/myappSourcepub fn config_file(&self, filename: &str) -> Result<PathBuf, MigrationError>
pub fn config_file(&self, filename: &str) -> Result<PathBuf, MigrationError>
Get a configuration file path.
This is a convenience method that joins the filename to the config directory. Creates the parent directory if it doesn’t exist.
§Arguments
filename- The configuration file name
§Example
let config_file = paths.config_file("config.toml")?;
// On Linux with System strategy: ~/.config/myapp/config.tomlSourcepub fn data_file(&self, filename: &str) -> Result<PathBuf, MigrationError>
pub fn data_file(&self, filename: &str) -> Result<PathBuf, MigrationError>
Get a data file path.
This is a convenience method that joins the filename to the data directory. Creates the parent directory if it doesn’t exist.
§Arguments
filename- The data file name
§Example
let data_file = paths.data_file("cache.db")?;
// On Linux with System strategy: ~/.local/share/myapp/cache.db