Function edres::codegen::define_structs_from_values
source · [−]pub fn define_structs_from_values(
data: &Struct,
struct_name: &str,
options: &Options
) -> Result<TokenStream, Error>
Expand description
Define a set of Rust structs based on the values 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 Map
s
from markup files.
Examples
let tokens = codegen::define_structs_from_values(
&Map::from_pairs([
("first", Value::Struct(Struct::from_pairs([
("name", Value::String("First".into())),
]))),
("second", Value::Struct(Struct::from_pairs([
("name", Value::String("Second".into())),
]))),
]),
"StructName",
&Options::minimal(),
).unwrap();
assert_eq!(tokens.to_string(), quote!(
#[allow(non_camel_case_types)]
pub struct StructName {
pub name: std::borrow::Cow<'static, str>,
}
).to_string());