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 env_tagged_seq_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.
Sourcefn env_tagged_seq_keys() -> Option<&'static [&'static str]>
fn env_tagged_seq_keys() -> Option<&'static [&'static str]>
Keys whose value is a sequence of single-key tagged tables (e.g. region_engine,
serialized from Vec<Enum> with externally tagged variants). Environment variables
address them by tag name (KEY__<TAG>__<FIELD>) instead of numeric index, and the
overrides are merged onto the corresponding default entries.
Keys must name a top-level field of the options struct: the default entries to merge onto are looked up by literal key in the serialized defaults, so a dotted key is rejected instead of silently leaving the defaults out of the merged sequence.
A configuration file that configures such a key as a whole replaces the merged value, so the environment variables for it are ineffective then and the file has to spell out every entry it wants.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".