Function cuicui_chirp::parse_dsl_impl::type_parsers
source · pub fn type_parsers<T, E, F>(overwrite_parsers: HashMap<Ident, F>)where
E: Into<Result<T>>,
F: Fn(&TypeRegistry, Option<&LoadContext<'_>>, &str) -> E,
Expand description
Use F
as parser for arguments of type Ident
.
Default: Handle<T> = args::to_handle, &str = args::quoted, _ = args::from_reflect
Note that only identifiers are supported (yet), so you can’t define custom parsers for references or generic types.
It is a series of key = value
pairs, key
is the type which parser must
be customized, and value
is the parser to use.
For parser, you can use args::to_handle
, args::quoted
, args::from_reflect
,
args::from_str
or any function that implements:
ⓘ
fn parse(
registry: &TypeRegistry,
ctx: Option<&LoadContext>,
input: &'a str,
) -> Result<T, anyhow::Error>;
Defaults
By default, parse_dsl_impl
uses the functions in the parse_dsl::args
module.
- For
Handle<T>
and&Handle<T>
, it usesargs::to_handle
- For
&str
, it usesargs::quoted
- For any other type, it uses
args::from_reflect
.
Example
ⓘ
use std::str::FromStr;
use css_color::parse_css_color;
use cuicui_chirp::parse_dsl_impl;
impl FromStr for Rule {
// ...
}
#[parse_dsl_impl(type_parsers(Color = parse_css_color, Rule = args::from_str))]
impl MyDsl {
pub fn color_and_rule(&mut self, color: Color, rule: Rule) {}
// ...