pub trait ParserConfig: Default {
type LexerConfig: LexerConfig;
// Required method
fn lexer_config(&self) -> Self::LexerConfig;
}Expand description
Parser config.
The purpose of parser config (as opposed to ParseOptions) is to allow setting options at either
compile time or runtime.
3 configs are provided:
NoTokensParserConfig: Parse without tokens, static (default)TokensParserConfig: Parse with tokens, staticRuntimeParserConfig: Parse with or without tokens, decided at runtime
The trade-off is:
-
The 2 static configs will produce better performance, because compiler can remove code that relates to the other option as dead code, and remove branches.
-
The runtime config will produce a smaller binary than using 2 different configs in the same application, which would cause 2 polymorphic variants of the parser to be compiled.
Advised usage:
- If your application uses only a specific set of options, use a static config.
- If your application uses multiple sets of options, probably a runtime config is preferable.
At present the only option controlled by ParserConfig is whether to parse with or without tokens.
Other options will be added in future.
You can also create your own config by implementing ParserConfig on a type.
Required Associated Types§
Sourcetype LexerConfig: LexerConfig
type LexerConfig: LexerConfig
Type of LexerConfig this ParserConfig uses.
Required Methods§
Sourcefn lexer_config(&self) -> Self::LexerConfig
fn lexer_config(&self) -> Self::LexerConfig
Get LexerConfig for this ParserConfig.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.