ParseDslImpl
macroGenerate ParseDsl
implementations to parse chirp files from an impl
block.
```text use cuicui_chirp::{ParseDslImpl, ParseDsl};
impl
// ...
#[parse_dsl(ignore)]
pub fn empty_px(&mut self, pixels: u16, cmds: &mut EntityCommands) -> Entity {
todo!()
}
} ```
All methods with a &mut self
argument
will automatically be added to the ParseDsl::method
implementation.
To ignore completely a function in the impl block, use #[parse_dsl(ignore)]
.
This relies on the FromStr
trait, each non-self argument to a method
should implement FromStr
, so that it is possible to parse it from a string.
For the snippet of code shown earlier, the macro output will be:
impl ParseDsl for LayoutDsl
as follow:text
impl<D: ParseDsl> ParseDsl for LayoutDsl<D> {
fn method(
&mut self,
data: cuicui_chirp::parse::InterpretMethodCtx,
) -> Result<(), cuicui_chirp::anyhow::Error> {
use cuicui_chirp::parse::{quick, InterpretMethodCtx, DslParseError, ParseType};
let InterpretMethodCtx { name, args } = data;
match name {
stringify!(column) => {
let args = quick::arg_0(args)?;
self.column();
Ok(())
}
stringify!(row) => {
let args = quick::arg_0(args)?;
self.row();
Ok(())
}
stringify!(rules) => {
let args = quick::arg_2(args)?;
self.rules(args.0, args.1);
Ok(())
}
name => {
self.inner.method(InterpretMethodCtx { name, args })
}
}
}
}