pub fn define_enum_from_keys(
    data: &Struct,
    enum_name: &str,
    source_file_path: Option<&Path>,
    options: &Options
) -> Result<TokenStream, Error>
Expand description

Define Rust enum based on the keys of the given key-value map.

While you can manually create a Map, the intended way to use this crate is to either use the functions in the root of this crate, or use the parsing module to read Maps from markup files.

Examples

let tokens = codegen::define_enum_from_keys(
    &Map::from_pairs([
        ("First", Value::I32(1)),
        ("Second", Value::I32(2)),
    ]),
    "EnumName",
    None,
    &Options::minimal(),
).unwrap();

assert_eq!(tokens.to_string(), quote!(
    pub enum EnumName {
        First,
        Second,
    }
).to_string());