Skip to main content

build_format

Function build_format 

Source
pub(super) fn build_format(
    field_map: &IndexMap<String, (Ident, TokenStream)>,
    input: &str,
    span: Span,
) -> TokenStream
Expand description

In the strings in the attributes supplied to this macro, we want callers to be able to reference fields in the format string. For example:

ⓘ
/// Suggest `==` when users wrote `===`.
#[suggestion("example message", code = "{lhs} == {rhs}")]
struct NotJavaScriptEq {
    #[primary_span]
    span: Span,
    lhs: Ident,
    rhs: Ident,
}

We want to automatically pick up that {lhs} refers self.lhs and {rhs} refers to self.rhs, then generate this call to format!:

ⓘ
format!("{lhs} == {rhs}", lhs = self.lhs, rhs = self.rhs)

This function builds the entire call to format!.