pub struct PrefPath { /* private fields */ }Expand description
Preference path manager for OS-recommended preference/configuration directories.
Unlike AppPaths, PrefPath strictly follows OS-specific conventions:
- macOS:
~/Library/Preferences/ - Linux:
~/.config/(XDG_CONFIG_HOME) - Windows:
%APPDATA%
§Example
ⓘ
use version_migrate::PrefPath;
let pref = PrefPath::new("com.example.myapp");
let pref_file = pref.pref_file("settings.plist")?;
// On macOS: ~/Library/Preferences/com.example.myapp/settings.plist
// On Linux: ~/.config/com.example.myapp/settings.plistImplementations§
Source§impl PrefPath
impl PrefPath
Sourcepub fn pref_dir(&self) -> Result<PathBuf, MigrationError>
pub fn pref_dir(&self) -> Result<PathBuf, MigrationError>
Get the preference directory path.
Creates the directory if it doesn’t exist.
§Returns
The resolved preference directory path:
- macOS:
~/Library/Preferences/{app_name} - Linux:
~/.config/{app_name} - Windows:
%APPDATA%\{app_name}
§Errors
Returns MigrationError::HomeDirNotFound if the home directory cannot be determined.
Returns MigrationError::IoError if directory creation fails.
§Example
ⓘ
let pref_dir = pref.pref_dir()?;
// On macOS: ~/Library/Preferences/com.example.myappSourcepub fn pref_file(&self, filename: &str) -> Result<PathBuf, MigrationError>
pub fn pref_file(&self, filename: &str) -> Result<PathBuf, MigrationError>
Get a preference file path.
This is a convenience method that joins the filename to the preference directory. Creates the parent directory if it doesn’t exist.
§Arguments
filename- The preference file name (e.g., “settings.plist”, “config.json”)
§Example
ⓘ
let pref_file = pref.pref_file("settings.plist")?;
// On macOS: ~/Library/Preferences/com.example.myapp/settings.plistTrait Implementations§
Auto Trait Implementations§
impl Freeze for PrefPath
impl RefUnwindSafe for PrefPath
impl Send for PrefPath
impl Sync for PrefPath
impl Unpin for PrefPath
impl UnwindSafe for PrefPath
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
Mutably borrows from an owned value. Read more