Match regular expressions into struct fields
This crate is inspired from alexflint/go-restructure
This crate uses a macro regexify!
which takes the struct along with its fields and patterns for sub-expressions.
extern crate restructure;
extern crate regex;
use Regex;
use ;
regexify!;
The regular expression that was executed was the concatenation of the struct tags:
(?P<domain>\w+)\.(?P<tld>\w+)
You can see that the fields which start with a _
are not added as captures into the regex. You can use _
with fields which act as seperators or whitespace.
The first submatch was inserted into the domain
field and the next into tld
field.
The general format of the macro is
regexify!;
regexify!
can deal with mixed type structs, making your work easier.
extern crate restructure;
extern crate regex;
use ;
use ;
use ;
regexify!;
What regexify!
does
Apart from declaring the struct specified, it also implements the RegexStruct
trait on the defined struct. It also applies the trait std::default::Default
on the struct.
TODO
- Nested structs
- Better error handling
- Iterable structs
- JSON conversion (optional)