pub struct ConfigManager<T> { /* private fields */ }Expand description
Manages one typed JSON settings file.
ConfigManager<T> stores and loads a complete configuration value of type
T. The type must implement Serde Serialize and DeserializeOwned.
The manager is intentionally small. It owns only:
- the directory containing the settings file,
- the settings file name, and
- the JSON output format.
Implementations§
Source§impl<T> ConfigManager<T>where
T: Serialize + DeserializeOwned,
impl<T> ConfigManager<T>where
T: Serialize + DeserializeOwned,
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a config manager using the OS-standard config directory and the current executable name.
On Windows desktop apps this resolves under %APPDATA%. Pure UWP apps
should use with_root_dir or the optional
uwp feature instead.
For production applications, prefer for_app because
it uses an explicit stable application identity instead of deriving one
from the executable file name.
Sourcepub fn for_app(app_name: &str) -> Result<Self>
pub fn for_app(app_name: &str) -> Result<Self>
Creates a config manager for an explicit application name.
This is the recommended desktop constructor for production apps because
the storage directory is stable even if the executable file name changes.
The app_name must be a single safe path component, not a path.
Sourcepub fn at_current_dir(self) -> Self
pub fn at_current_dir(self) -> Self
Stores the settings file in the current working directory.
Sourcepub fn with_root_dir<P: Into<PathBuf>>(self, path: P) -> Self
pub fn with_root_dir<P: Into<PathBuf>>(self, path: P) -> Self
Stores the settings file in a caller-provided directory.
This is the primary compatibility seam for sandboxed hosts, including Pure UWP. The host application may resolve its application data directory and pass it here.
Sourcepub fn at_custom_dir<P: Into<PathBuf>>(self, path: P) -> Self
pub fn at_custom_dir<P: Into<PathBuf>>(self, path: P) -> Self
Stores the settings file in a caller-provided directory.
This method is kept for compatibility with v2.0.x. Prefer
with_root_dir in new code.
Sourcepub fn with_filename(self, name: &str) -> Self
pub fn with_filename(self, name: &str) -> Self
Changes the settings file name without validation.
This method is retained for v2.x compatibility. New code should prefer
try_with_filename, which rejects path-like
names such as ../settings.json.
Sourcepub fn try_with_filename(self, name: &str) -> Result<Self>
pub fn try_with_filename(self, name: &str) -> Result<Self>
Changes the settings file name after validating it as a plain file name.
The accepted value must be a single file name, not an absolute path and not a relative path containing directory traversal.
Sourcepub fn disable_pretty_json(self) -> Self
pub fn disable_pretty_json(self) -> Self
Stores JSON in compact form instead of pretty-printed form.
Sourcepub fn folder_path(&self) -> &Path
pub fn folder_path(&self) -> &Path
Returns the settings folder path.
Source§impl<T> ConfigManager<T>
impl<T> ConfigManager<T>
Trait Implementations§
Source§impl<T: Clone> Clone for ConfigManager<T>
impl<T: Clone> Clone for ConfigManager<T>
Source§fn clone(&self) -> ConfigManager<T>
fn clone(&self) -> ConfigManager<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more