Skip to content

Commit

Permalink
[#36] Handle inner structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Orchaldir committed Sep 10, 2023
1 parent a67f2ee commit d63ecfe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion macro_ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ fn parse_struct_field(field: &Field) -> TokenStream2 {
#field_name: parser.parse_u32(&format!("{}.{}", path, stringify!(#field_name)), 0),
}
} else {
quote! {}
let name = &get_field_type(field);
quote! {
#field_name: #name::parse(parser, &format!("{}.{}", path, stringify!(#field_name)), &format!(" {}", spaces)),
}
}
}

Expand Down
18 changes: 11 additions & 7 deletions rpg_tools_core/examples/parser_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,24 @@ use std::collections::HashMap;

use macro_ui::ui;

#[derive(ui, Debug, Default)]
pub struct Inner {
pub c: u32,
}

#[derive(ui, Debug, Default)]
pub struct Test {
pub a: u32,
pub b: u32,
}

impl Test {
pub fn new(a: u32, b: u32) -> Self {
Self { a, b }
}
pub inner: Inner,
}

fn main() {
let parser = MockParser::new(HashMap::from([("test.a", "2"), ("test.b", "3")]));
let parser = MockParser::new(HashMap::from([
("test.a", "2"),
("test.b", "3"),
("test.inner.c", "4"),
]));
let test = Test::parse(&parser, "test", "");
println!("Values:{:?}", test);
}

0 comments on commit d63ecfe

Please sign in to comment.