pub trait Storable: Serialize + Sized {
// Required method
fn path(&self) -> &Path;
// Provided methods
fn store_with_specific_format(
&self,
config_type: ConfigFormat,
) -> Result<()> { ... }
fn store(&self) -> Result<()> { ... }
fn store_without_overwrite(&self) -> Result<()> { ... }
}Expand description
A more easy way to store a struct into a configuration file.
Just impl Storable::path(&self) -> &Path; to your struct, and then you can
use store_with_specific_format, store, store_without_overwrite
directly by calling the method on your struct.
Required Methods§
Provided Methods§
Sourcefn store_with_specific_format(&self, config_type: ConfigFormat) -> Result<()>
fn store_with_specific_format(&self, 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::FileAccessif the file cannot be written. - Returns
Error::UnsupportedFormatif the file extension is not supported. - Returns
Error::<Format>if serialization to file fails.
Sourcefn store(&self) -> Result<()>
fn store(&self) -> Result<()>
Store config file to path. If the file already exists, the config file will be overwritten.
§Errors
- Returns
Error::UnsupportedFormatif the file extension is not supported. - Returns
Error::<Format>if serialization to file fails.
Sourcefn store_without_overwrite(&self) -> Result<()>
fn store_without_overwrite(&self) -> Result<()>
Store config file to path, if path exists, return error
§Errors
- Returns
Error::FileExistsif the file already exists. - Returns
Error::UnsupportedFormatif 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.