pub(crate) trait HasFieldMap {
// Required method
fn get_field_binding(&self, field: &String) -> Option<&TokenStream>;
// Provided method
fn build_format(&self, input: &str, span: Span) -> TokenStream { ... }
}Required Methods§
Sourcefn get_field_binding(&self, field: &String) -> Option<&TokenStream>
fn get_field_binding(&self, field: &String) -> Option<&TokenStream>
Returns the binding for the field with the given name, if it exists on the type.
Provided Methods§
Sourcefn build_format(&self, input: &str, span: Span) -> TokenStream
fn build_format(&self, input: &str, span: Span) -> TokenStream
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(slug = "parser-not-javascript-eq", 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!.