Macro smart_config::config
source · macro_rules! config { ($($path:tt : $value:expr),* $(,)?) => { ... }; }
Expand description
Creates Json
configuration input based on the provided list of path–value tuples.
This is essentially a slightly fancier / more specialized version of json!
.
A path must be a string literal, with segments separated by dots .
. A value can be anything
implementing Serialize
. Paths in a macro cannot coincide or be embedded into each other.
The value produced by macro has Json
type.
§Examples
§Basic usage
let json = smart_config::config!(
"test.int": 1,
"test.str": "example",
"test.flag": true,
"test.structured.array": [1, 2, 3],
);
// Will create JSON input with an object at `test` with `int`, `str`, `flag`,
// and `structured` fields, where `structured` is an object with `array` field.
§Compilation-time checks
ⓘ
let json = smart_config::config!(
"test": false,
"test.int": 123,
// Compilation error: Path #0 `test` is a prefix of path #1 `test.int`
);