pub trait StoreConfigFile {
// Required method
fn store_with_specific_format(
&self,
path: impl AsRef<Path>,
config_type: ConfigFormat,
) -> Result<()>;
// Provided methods
fn store(&self, path: impl AsRef<Path>) -> Result<()>
where Self: Sized { ... }
fn store_without_overwrite(&self, path: impl AsRef<Path>) -> Result<()>
where Self: Sized { ... }
}
Expand description
Trait for storing a struct into a configuration file.
This trait is automatically implemented when serde::Serialize
is.
Required Methods§
Sourcefn store_with_specific_format(
&self,
path: impl AsRef<Path>,
config_type: ConfigFormat,
) -> Result<()>
fn store_with_specific_format( &self, path: impl AsRef<Path>, config_type: ConfigFormat, ) -> Result<()>
Store config file to path with specific format, do not use extension to determine. If the file already exists, the config file will be overwritten.
§Errors
- Returns
Error::FileAccess
if the file cannot be written. - Returns
Error::UnsupportedFormat
if the file extension is not supported. - Returns
Error::<Format>
if serialization to file fails.
Provided Methods§
Sourcefn store(&self, path: impl AsRef<Path>) -> Result<()>where
Self: Sized,
fn store(&self, path: impl AsRef<Path>) -> Result<()>where
Self: Sized,
Store config file to path. If the file already exists, the config file will be overwritten.
§Errors
- Returns
Error::UnsupportedFormat
if the file extension is not supported. - Returns
Error::<Format>
if serialization to file fails.
Sourcefn store_without_overwrite(&self, path: impl AsRef<Path>) -> Result<()>where
Self: Sized,
fn store_without_overwrite(&self, path: impl AsRef<Path>) -> Result<()>where
Self: Sized,
Store config file to path, if path exists, return error
§Errors
- Returns
Error::FileExists
if the file already exists. - Returns
Error::UnsupportedFormat
if the file extension is not supported. - Returns
Error::<Format>
if serialization to file fails.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.