pub trait Configurable:
Serialize
+ DeserializeOwned
+ Default
+ Sized {
// Provided methods
fn load_layered_options(
config_file: Option<&str>,
env_prefix: &str,
) -> Result<Self> { ... }
fn validate_sanitize(&mut self) -> Result<()> { ... }
fn env_list_keys() -> Option<&'static [&'static str]> { ... }
fn to_toml(&self) -> Result<String> { ... }
}
Expand description
Configuration trait defines the common interface for configuration that can be loaded from multiple sources and serialized to TOML.
Provided Methods§
Sourcefn load_layered_options(
config_file: Option<&str>,
env_prefix: &str,
) -> Result<Self>
fn load_layered_options( config_file: Option<&str>, env_prefix: &str, ) -> Result<Self>
Load the configuration from multiple sources and merge them.
The precedence order is: config file > environment variables > default values.
env_prefix
is the prefix of environment variables, e.g. “FRONTEND__xxx”.
The function will use dunder(double underscore) __
as the separator for environment variables, for example:
DATANODE__STORAGE__MANIFEST__CHECKPOINT_MARGIN
will be mapped to DatanodeOptions.storage.manifest.checkpoint_margin
field in the configuration.
list_keys
is the list of keys that should be parsed as a list, for example, you can pass Some(&["meta_client_options.metasrv_addrs"]
to parse GREPTIMEDB_METASRV__META_CLIENT_OPTIONS__METASRV_ADDRS
as a list.
The function will use comma ,
as the separator for list values, for example: 127.0.0.1:3001,127.0.0.1:3002,127.0.0.1:3003
.
Sourcefn validate_sanitize(&mut self) -> Result<()>
fn validate_sanitize(&mut self) -> Result<()>
Validate(and possibly sanitize) the configuration.
Sourcefn env_list_keys() -> Option<&'static [&'static str]>
fn env_list_keys() -> Option<&'static [&'static str]>
List of toml keys that should be parsed as a list.
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.