Struct conrig::path::ConfigPathMetadata
source · pub struct ConfigPathMetadata<'p, 'cn> {
pub project_path: ProjectPath<'p>,
pub config_name: &'cn [&'cn str],
pub default_format: FileFormat,
pub config_option: ConfigOption,
}Expand description
The main entry point of conrig.
This defines multiple configuration options for your application.
See the crate’s documentation for more information.
Fields§
§project_path: ProjectPath<'p>Your application’s project path.
See directories::ProjectDirs for more information.
config_name: &'cn [&'cn str]Your configuration files’ names.
At least one should be specified.
default_format: FileFormatThe default language of your configuration files.
config_option: ConfigOptionExtra configuration options.
Implementations§
source§impl<'p, 'cn> ConfigPathMetadata<'p, 'cn>
impl<'p, 'cn> ConfigPathMetadata<'p, 'cn>
sourcepub const fn new(
project_path: ProjectPath<'p>,
config_name: &'cn [&'cn str],
default_format: FileFormat,
config_option: ConfigOption
) -> Self
pub const fn new( project_path: ProjectPath<'p>, config_name: &'cn [&'cn str], default_format: FileFormat, config_option: ConfigOption ) -> Self
Create a new ConfigPathMetadata.
sourcepub const fn with_project_path(self, project_path: ProjectPath<'p>) -> Self
pub const fn with_project_path(self, project_path: ProjectPath<'p>) -> Self
Modify the project_path field.
sourcepub const fn with_config_name(self, config_name: &'cn [&'cn str]) -> Self
pub const fn with_config_name(self, config_name: &'cn [&'cn str]) -> Self
Modify the config_name field.
sourcepub const fn with_default_format(self, default_format: FileFormat) -> Self
pub const fn with_default_format(self, default_format: FileFormat) -> Self
Modify the default_format field.
sourcepub const fn no_default_format(self) -> Self
pub const fn no_default_format(self) -> Self
Set the default_format to DEFAULT_FILE_FORMAT.
sourcepub const fn with_config_option(self, config_option: ConfigOption) -> Self
pub const fn with_config_option(self, config_option: ConfigOption) -> Self
Modify the config_option field.
sourcepub fn sys_config_dir(&self) -> Option<PathBuf>
pub fn sys_config_dir(&self) -> Option<PathBuf>
Get the configuration directory of your application.
See directories::ProjectDirs::config_dir for more information.
sourcepub fn sys_preference_dir(&self) -> Option<PathBuf>
pub fn sys_preference_dir(&self) -> Option<PathBuf>
Get the preference directory of your application.
See directories::ProjectDirs::preference_dir for more information.
sourcepub fn sys_dir(&self) -> Option<PathBuf>
pub fn sys_dir(&self) -> Option<PathBuf>
Get the system-level config directory of your application.
Depends on ConfigOption.config_sys_type:
sourcepub fn default_sys_config_file(&self) -> Result<PathBuf, ConrigError>
pub fn default_sys_config_file(&self) -> Result<PathBuf, ConrigError>
Format the default system-level configuration file.
sourcepub fn default_local_config_file(&self) -> Result<PathBuf, ConrigError>
pub fn default_local_config_file(&self) -> Result<PathBuf, ConrigError>
Format the default configuration file in the current folder.
sourcepub fn default_config_file(&self) -> Result<PathBuf, ConrigError>
pub fn default_config_file(&self) -> Result<PathBuf, ConrigError>
Format the default configuration file, depending on the ConfigOption.sys_override_local.
sourcepub fn search_config_file<'a>(
&'a self
) -> Result<ConfigFile<'a, 'p, 'cn>, ConrigError>
pub fn search_config_file<'a>( &'a self ) -> Result<ConfigFile<'a, 'p, 'cn>, ConrigError>
Search for a configuration file.
This will check for two places:
- Your system-level configuration directory.
- The current directory.
The sequence is determined by ConfigOption.sys_override_local.
sourcepub fn read<T: DeserializeOwned>(&self) -> Result<T, ConrigError>
pub fn read<T: DeserializeOwned>(&self) -> Result<T, ConrigError>
Read a configuration file, using the default searching method.
This is equivalent to
self.search_config_file()?.fallback_default()?.read().
sourcepub fn write<T: Serialize>(&self, value: &T) -> Result<(), ConrigError>
pub fn write<T: Serialize>(&self, value: &T) -> Result<(), ConrigError>
Write into a configuration file, using the default searching method.
This is equivalent to
self.search_config_file()?.fallback_default()?.write(&foo).
sourcepub fn read_or_default<T: Serialize + DeserializeOwned + Default>(
&self
) -> Result<T, ConrigError>
pub fn read_or_default<T: Serialize + DeserializeOwned + Default>( &self ) -> Result<T, ConrigError>
Read a configuration file, or creating a new one with the default value.
This is equivalent to
self.search_config_file()?.fallback_default()?.read_or_default::<T>().
sourcepub fn read_or_new<T: Serialize + DeserializeOwned>(
&self,
default: T
) -> Result<T, ConrigError>
pub fn read_or_new<T: Serialize + DeserializeOwned>( &self, default: T ) -> Result<T, ConrigError>
Read a configuration file, or creating a new one with the default value provided.
This is equivalent to
self.search_config_file()?.fallback_default()?.read_or_default::<T>().
Trait Implementations§
source§impl<'p, 'cn> Clone for ConfigPathMetadata<'p, 'cn>
impl<'p, 'cn> Clone for ConfigPathMetadata<'p, 'cn>
source§fn clone(&self) -> ConfigPathMetadata<'p, 'cn>
fn clone(&self) -> ConfigPathMetadata<'p, 'cn>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl<'p, 'cn> Debug for ConfigPathMetadata<'p, 'cn>
impl<'p, 'cn> Debug for ConfigPathMetadata<'p, 'cn>
source§impl<'p, 'cn> PartialEq for ConfigPathMetadata<'p, 'cn>
impl<'p, 'cn> PartialEq for ConfigPathMetadata<'p, 'cn>
source§fn eq(&self, other: &ConfigPathMetadata<'p, 'cn>) -> bool
fn eq(&self, other: &ConfigPathMetadata<'p, 'cn>) -> bool
self and other values to be equal, and is used
by ==.impl<'p, 'cn> Eq for ConfigPathMetadata<'p, 'cn>
impl<'p, 'cn> StructuralPartialEq for ConfigPathMetadata<'p, 'cn>
Auto Trait Implementations§
impl<'p, 'cn> Freeze for ConfigPathMetadata<'p, 'cn>
impl<'p, 'cn> RefUnwindSafe for ConfigPathMetadata<'p, 'cn>
impl<'p, 'cn> Send for ConfigPathMetadata<'p, 'cn>
impl<'p, 'cn> Sync for ConfigPathMetadata<'p, 'cn>
impl<'p, 'cn> Unpin for ConfigPathMetadata<'p, 'cn>
impl<'p, 'cn> UnwindSafe for ConfigPathMetadata<'p, 'cn>
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<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.