pub trait FormatMacroGenerator {
// Required methods
fn finalize(self) -> Result<TokenStream>;
fn string_fragment(&mut self, string: &str) -> Result<()>;
fn integer_conversion(
&mut self,
params: &FormatParams,
signed: bool,
type_width: u8,
expression: Arg,
) -> Result<()>;
fn string_conversion(&mut self, expression: Arg) -> Result<()>;
fn char_conversion(&mut self, expression: Arg) -> Result<()>;
// Provided method
fn untyped_conversion(
&mut self,
_expression: Arg,
_params: &FormatParams,
) -> Result<()> { ... }
}Expand description
A code generator for implementing a pw_format style macro.
This trait serves as the primary interface between pw_format and a
proc macro using it to implement format string and argument parsing. When
evaluating the proc macro and generating code, generate will make
repeated calls to string_fragment
and the conversion functions. These calls will be made in the order they
appear in the format string. After all fragments and conversions are
processed, generate will call
finalize.
For an example of implementing a FormatMacroGenerator see the
pw_format_example_macro crate.
Required Methods§
Sourcefn finalize(self) -> Result<TokenStream>
fn finalize(self) -> Result<TokenStream>
Sourcefn string_fragment(&mut self, string: &str) -> Result<()>
fn string_fragment(&mut self, string: &str) -> Result<()>
Process a string fragment.
A string fragment is a string of characters that appear in a format
string. This is different than a
string_conversion which is
a string provided through a conversion specifier (i.e. "%s").
Sourcefn integer_conversion(
&mut self,
params: &FormatParams,
signed: bool,
type_width: u8,
expression: Arg,
) -> Result<()>
fn integer_conversion( &mut self, params: &FormatParams, signed: bool, type_width: u8, expression: Arg, ) -> Result<()>
Process an integer conversion.
Sourcefn string_conversion(&mut self, expression: Arg) -> Result<()>
fn string_conversion(&mut self, expression: Arg) -> Result<()>
Process a string conversion.
See string_fragment for a
disambiguation between that function and this one.
Sourcefn char_conversion(&mut self, expression: Arg) -> Result<()>
fn char_conversion(&mut self, expression: Arg) -> Result<()>
Process a character conversion.
Provided Methods§
Sourcefn untyped_conversion(
&mut self,
_expression: Arg,
_params: &FormatParams,
) -> Result<()>
fn untyped_conversion( &mut self, _expression: Arg, _params: &FormatParams, ) -> Result<()>
Process an untyped conversion.