codgenhelp

Crates.iocodgenhelp
lib.rscodgenhelp
version0.0.1
sourcesrc
created_at2017-01-02 22:42:47.44191
updated_at2017-01-02 22:42:47.44191
descriptionSimplifies structure and enum parsing in Macros1.1
homepagehttps://github.com/valarauca/macrohelper
repositoryhttps://github.com/valarauca/macrohelper
max_upload_size
id7894
size2,264,717
Cody Laeder (valarauca)

documentation

https://valarauca.github.io/macrohelper/macrohelper/index.html

README

Codegen Help

Docs

Simplifies the interaction with the syn parser. Normally I find when working with codegen extensions a lot of extra information is supplied to the developer a certain amount of this is noise.

This is my attempt to filter out the noise. As well as provide useful tools to allow for Rust Dev's to interact with partially compiled Rust Code.

.

To use this crate:

depedencies
codgenhelp = "0.0.1"

Below you can find some examples:

Both MacroInput::from_str and MacroInput::new(TokenTree) are exposed to construct the MacroInput type

####Simple Enum Example

//the example string
let dut = r#"

    #[DoTheThing = 15 ]
    pub enum ValEnum {
        Foo,
        Bar
    }
"#;

//attempt to parse
let dut = MacroInput::from_str(dut).unwrap();

//check the attr
assert!( dut.attr.len() == 1);
assert_eq!( dut.attr[0].get_name().unwrap(), "DoTheThing");
assert_eq!( dut.attr[0].from_literal().unwrap(), FromLiteral::Int(15));

//check the id
assert_eq!( &dut.id, "ValEnum");

//check the body
assert!( dut.body.is_enum() );
let body = dut.body.get_enum().unwrap();
assert_eq!(body.len(), 2);
assert!( body[0].data.is_unit());
assert_eq!( body[0].get_name(), "Foo");
assert!( body[1].data.is_unit());
assert_eq!( body[1].get_name(), "Bar");
assert!(body.is_unit());

####Simple Struct Example

//the example string
let dut = r"

    #[get]
    pub struct Thing {
        a: i64
    }
";

//attempt to parse
let dut = MacroInput::from_str(dut).unwrap();

//check the attr
assert!( dut.attr.len() == 1);
assert!( dut.attr[0].is_word());
assert_eq!( dut.attr[0].get_name().unwrap(), "get");

//check the id
assert_eq!( dut.id, "Thing");

//check the body
assert!( dut.body.is_struct() );
let body = dut.body.get_struct().unwrap();
assert!( body.is_norm());
let fields = body.get_fields().unwrap();
assert_eq!( fields.len(), 1 );
assert_eq!( fields[0].get_name().unwrap(), "a");
Commit count: 0

cargo fmt