from_static_map

Macro from_static_map 

Source
macro_rules! from_static_map {
    ( $ty:ty, { $( $key:expr => $value:expr ),* $(,)? } ) => { ... };
}
Expand description

Macro to generate config instance from a map of key-value pairs. The keys in the map are config keys, e.g. “port”. The values in the map are string values, e.g. “8080”. This macro will panic if any required config is missing or if any config value cannot be parsed into the expected type.

§Example

use cfg_rs::*;
#[derive(Debug, FromConfig)]
struct AppConfig {
   port: u16,
  host: String,
}
let config: AppConfig = from_static_map!(AppConfig, {
   "port" => "8080",
  "host" => "localhost",
});
assert_eq!(config.port, 8080);
assert_eq!(config.host, "localhost");

Note: This macro is intended for use in tests or examples where you want to quickly create a config instance from inline key-value pairs. It is not recommended for use in production code.