ConfigWritable

Trait ConfigWritable 

Source
pub trait ConfigWritable: Serialize {
    // Required methods
    fn save_path(&self) -> String;
    fn save_folder(&self) -> String;

    // Provided methods
    fn as_json(&self, action: String) -> Result<String, EpochError> { ... }
    fn save_with_context(
        &self,
        action_description: &str,
        do_not_erase: &SaveMode,
    ) -> Result<(), EpochError> { ... }
}
Expand description

Trait representing a serialisable / writable config

Required Methods§

Source

fn save_path(&self) -> String

The full path indicating where to save the config

Source

fn save_folder(&self) -> String

The folder where to save the file to save the config

Provided Methods§

Source

fn as_json(&self, action: String) -> Result<String, EpochError>

Serialises the config into a pretty JSON string.

§Arguments
  • action - A description of the action for error reporting.
§Returns
  • Ok(String) containing the pretty-printed JSON.
  • Err(EpochError::Serde) if serialisation fails.
Source

fn save_with_context( &self, action_description: &str, do_not_erase: &SaveMode, ) -> Result<(), EpochError>

Saves the config into its nominal path.

Existing subdirectories are not created. If do_not_erase is SaveMode::Erase, an existing file is overwritten. If do_not_erase is SaveMode::DoNotErase, an error is returned when the file already exists.

§Arguments
  • action_description - A human-readable description used in error messages.
  • do_not_erase - Determines whether to overwrite an existing file.
§Returns
  • Ok(()) on success.
  • Err(EpochError::ConfigWrite) on any serialization error.
  • Err(EpochError::ConfigCreation) on any I/O error.

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.

Implementors§