[][src]Function config_struct::generate_enum_from_source

pub fn generate_enum_from_source<S: AsRef<str>>(
    source: S,
    options: &EnumOptions
) -> Result<String, GenerationError>

Generate Rust source code defining an enum from a config string containing a map-like structure. The variants of the enum are based on the keys of the map.

The format must be specified in the provided options.

Examples

use config_struct::{EnumOptions, Format};

let code = config_struct::generate_enum_from_source(
    "[KeyOne]\n[KeyTwo]\n",
    &EnumOptions {
        format: Some(Format::Toml),
        ..Default::default()
    })?;
eprintln!("CODE : {}", code);

assert!(code.contains("pub enum Key"));
assert!(code.contains("KeyOne"));
assert!(code.contains("KeyTwo"));