ConfigManager

Trait ConfigManager 

Source
pub trait ConfigManager {
    // Required methods
    fn config_file_path(&self) -> String;
    fn encode_pretty(&self, pretty_format: bool) -> String;
    fn decode(&self, json_string: &str);

    // Provided methods
    fn load(&self) -> bool { ... }
    fn load_bak(&self) -> bool { ... }
    fn persist_with_topic(&mut self, _topic_name: &str, _t: Box<dyn Any>) { ... }
    fn persist_map(&mut self, _m: &HashMap<String, Box<dyn Any>>) { ... }
    fn persist(&self) { ... }
    fn decode0(&mut self, _key: &[u8], _body: &[u8]) { ... }
    fn stop(&mut self) -> bool { ... }
    fn encode(&self) -> String { ... }
}

Required Methods§

Source

fn config_file_path(&self) -> String

Returns the file path for the configuration file.

This method should be implemented to return the path of the configuration file that the ConfigManager will use to load or persist the configuration.

§Returns

A String representing the path of the configuration file.

Source

fn encode_pretty(&self, pretty_format: bool) -> String

Encodes the current configuration into a String with an option for pretty formatting.

This method encodes the current configuration into a String. It offers an option to format the output in a more readable (pretty) format if pretty_format is true.

§Arguments
  • pretty_format - A boolean indicating whether the output should be pretty formatted.
§Returns

A String representing the encoded configuration, optionally in a pretty format.

Source

fn decode(&self, json_string: &str)

Decodes the configuration from a JSON string.

This method takes a JSON string representation of the configuration and decodes it into the internal representation used by the ConfigManager. Implementations should update the internal state based on the provided JSON string.

§Arguments
  • json_string - A &str representing the configuration in JSON format.

Provided Methods§

Source

fn load(&self) -> bool

Loads the configuration from a file.

This method attempts to load the configuration from a file whose path is returned by config_file_path. If the file content is empty, it attempts to load from a backup file. If the file content is not empty, it decodes the content and logs a success message.

§Returns
  • true if the configuration is successfully loaded and decoded.
  • false if the configuration loading fails.
Source

fn load_bak(&self) -> bool

Loads the configuration from a backup file.

This method attempts to load the configuration from a backup file whose path is returned by config_file_path with “.bak” appended. If the file content is not empty, it decodes the content and logs a success message.

§Returns
  • true if the configuration is successfully loaded and decoded.
  • false if the configuration loading fails.
Source

fn persist_with_topic(&mut self, _topic_name: &str, _t: Box<dyn Any>)

Persists the configuration with a topic.

This method persists the configuration with a given topic. The actual implementation is delegated to the persist method.

Source

fn persist_map(&mut self, _m: &HashMap<String, Box<dyn Any>>)

Persists the configuration with a map.

This method persists the configuration with a given map. The actual implementation is delegated to the persist method.

Source

fn persist(&self)

Persists the configuration.

This method persists the configuration to a file whose path is returned by config_file_path. If the encoded configuration is not empty, it writes the configuration to the file.

Source

fn decode0(&mut self, _key: &[u8], _body: &[u8])

Decodes the configuration.

This method is a placeholder for decoding the configuration. The actual implementation should be provided by the implementer of the trait.

Source

fn stop(&mut self) -> bool

Stops the configuration manager.

This method is a placeholder for stopping the configuration manager. The actual implementation should be provided by the implementer of the trait.

§Returns
  • true by default.
Source

fn encode(&self) -> String

Encodes the current configuration into a String.

This method leverages encode_pretty with pretty_format set to false to encode the current configuration into a compact String representation.

§Returns

A String representing the encoded configuration in a compact format.

Implementors§