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: FileFormat

The default language of your configuration files.

§config_option: ConfigOption

Extra configuration options.

Implementations§

source§

impl<'p, 'cn> ConfigPathMetadata<'p, 'cn>

source

pub const fn new( project_path: ProjectPath<'p>, config_name: &'cn [&'cn str], default_format: FileFormat, config_option: ConfigOption ) -> Self

Create a new ConfigPathMetadata.

source

pub const fn with_project_path(self, project_path: ProjectPath<'p>) -> Self

Modify the project_path field.

source

pub const fn with_config_name(self, config_name: &'cn [&'cn str]) -> Self

Modify the config_name field.

source

pub const fn with_default_format(self, default_format: FileFormat) -> Self

Modify the default_format field.

source

pub const fn no_default_format(self) -> Self

source

pub const fn with_config_option(self, config_option: ConfigOption) -> Self

Modify the config_option field.

source

pub fn sys_config_dir(&self) -> Option<PathBuf>

Get the configuration directory of your application.

See directories::ProjectDirs::config_dir for more information.

source

pub fn sys_preference_dir(&self) -> Option<PathBuf>

Get the preference directory of your application.

See directories::ProjectDirs::preference_dir for more information.

source

pub fn sys_dir(&self) -> Option<PathBuf>

Get the system-level config directory of your application.

Depends on ConfigOption.config_sys_type:

source

pub fn default_sys_config_file(&self) -> Result<PathBuf, ConrigError>

Format the default system-level configuration file.

source

pub fn default_local_config_file(&self) -> Result<PathBuf, ConrigError>

Format the default configuration file in the current folder.

source

pub fn default_config_file(&self) -> Result<PathBuf, ConrigError>

Format the default configuration file, depending on the ConfigOption.sys_override_local.

source

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:

The sequence is determined by ConfigOption.sys_override_local.

source

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().

source

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).

source

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>().

source

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>

source§

fn clone(&self) -> ConfigPathMetadata<'p, 'cn>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'p, 'cn> Debug for ConfigPathMetadata<'p, 'cn>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'p, 'cn> PartialEq for ConfigPathMetadata<'p, 'cn>

source§

fn eq(&self, other: &ConfigPathMetadata<'p, 'cn>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<'p, 'cn> Eq for ConfigPathMetadata<'p, 'cn>

source§

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> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.