Expand description
§esp-config
§Documentation
§Usage
esp-config takes a prefix (usually the crate name) and a set of configuration keys and default values to produce a configuration system that supports:
- Emitting rustc cfg’s for boolean keys
- Emitting environment variables for numbers
- Along with decimal parsing, it supports Hex, Octal and Binary with the respective
0x,0oand0bprefixes.
- Along with decimal parsing, it supports Hex, Octal and Binary with the respective
- Emitting environment variables string values
§Viewing the configuration
The possible configuration values are output as a markdown table in the crates OUT_DIR with the format {prefix}_config_table.md, this can then be included into the crates top level documentation. Here is an example of the output:
| Name | Description | Default value |
|---|---|---|
| ESP_HAL_PLACE_SPI_DRIVER_IN_RAM | Places the SPI driver in RAM for better performance | false |
§Setting configuration options
For any available configuration option, the environment variable or cfg is always set based on the default value specified in the table. Users can override this by setting environment variables locally in their shell or the preferred option is to utilize cargo’s env section.
It’s important to note that due to a bug in cargo, any modifications to the environment, local or otherwise will only get picked up on a full clean build of the project.
To see the final selected configuration another table is output to the OUT_DIR with the format {prefix}_selected_config.md.
§Capturing configuration values in the downstream crate
For all supported data types, there are helper macros that emit const code for parsing the configuration values.
- Numbers -
esp_config_int!(integer_type, "ENV") - Strings -
esp_config_str!("ENV") - Bool -
esp_config_bool!("ENV")
In addition to environment variables, for boolean types rust cfg’s are emitted in snake case without the prefix.
§Minimum Supported Rust Version (MSRV)
This crate is guaranteed to compile when using the latest stable Rust version at the time of the crate’s release. It might compile with older versions, but that may change in any new release, including patches.
§License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
§Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
§Feature Flags
build— Enable the generation and parsing of a config
Macros§
- esp_
config_ bool - Parse the value of an environment variable as a bool at compile time.
- esp_
config_ int - Parse the value of an environment variable as an integer at compile time.
- esp_
config_ str - Get the string value of an environment variable at compile time.
Structs§
- Config
Option - A configuration option.
Enums§
- Display
Hint - A display hint (for tooling only)
- Error
- Configuration errors.
- Stability
- The stability of the configuration option.
- Validator
- Configuration value validation functions.
- Value
- Supported configuration value types.
Functions§
- generate_
config - Generate and parse config from a prefix, and an array tuples containing the name, description, default value, and an optional validator.