Expand description
The macro module provides helpers that simplify writing proc macros
that take format strings and arguments. This is accomplish with three
main constructs:
FormatAndArgsFlavor: A struct that implements syn::parse::Parse to parse a format string and its following arguments.FormatMacroGenerator: A trait used to implement the macro specific logic to generate code.generate: A function to handle the execution of the proc macro by calling into a FormatMacroGenerator.
Additionally PrintfFormatMacroGenerator trait and generate_printf
function are provided to help when implementing generators that need to
produce printf style format strings as part of their code generation.
§Example
An example of implementing a proc macro is provided in the pw_format_example_macro crate
Structs§
- Core
FmtFormat String Parser - An implementation of
FormatStringParserthat parserscore::fmtstyle format strings. - Error
- An error occurring during proc macro evaluation.
- Format
AndArgs - A parsed format string and it’s arguments.
- Format
AndArgs Flavor - A variant of
FormatAndArgsthat is generic over format string flavor. - Format
Params - Formatting parameters passed to an untyped conversion.
- Printf
Format String Parser - An implementation of
FormatStringParserthat parsersprintfstyle format strings.
Enums§
- Arg
- An argument to a
pw_formatbacked macro. - Printf
Format String Fragment - A fragment of a printf format string.
Traits§
- Core
FmtFormat Macro Generator - A specialized generator for proc macros that produce
core::fmtstyle format strings. - Format
Macro Generator - A code generator for implementing a
pw_formatstyle macro. - Format
String Parser - A trait for parsing a string into a
FormatString. - Printf
Format Macro Generator - A specialized generator for proc macros that produce
printfstyle format strings.
Functions§
- generate
- Generate code for a
pw_formatstyle proc macro. - generate_
core_ fmt - Generate code for a
pw_formatstyle proc macro that needs acore::fmtformat string. - generate_
printf - Generate code for a
pw_formatstyle proc macro that needs aprintfformat string.
Type Aliases§
- Result
- An alias for a Result with an
Error