pub trait IdentFrag: Spanned {
type BadIdent: Clone;
// Required methods
fn frag_to_tokens(
&self,
out: &mut TokenStream,
) -> Result<(), Self::BadIdent>;
fn fragment(&self) -> String;
// Provided method
fn note_atoms(&self, out: &mut Vec<AtomForReport>) { ... }
}Expand description
For use with ExpansionOutput.append_identfrag_toks etc.
Sort of like quote::IdentFragment.
But:
- Strings available directly, not via the inconvenient
fmt, - identifier construction doesn’t involve
format_ident!and panics. paste::InputAtompassed through separately,
The main purpose of this trait is to allow deferral of errors
from constructing bad identifiers. Some inputs (implementors
of IdentFrag, typically those which are already tokens) can
infallibly be appended as tokens.
But paste results aren’t converted to identifiers until the last
moment: they can’tbed converted infallibly, and the error surfaces
in convert_to_ident.
The framework methods append_*ident* propagate any error to the
call site. Call sites which pass already-tokens can just use ?
to convert the uninhabited error to syn::Error - or they can
use IdentFragInfallible::unreachable.
Call sites which pass actually-fallible content (ie, paste results)
end up with a syn::Error.
Required Associated Types§
Required Methods§
Sourcefn frag_to_tokens(&self, out: &mut TokenStream) -> Result<(), Self::BadIdent>
fn frag_to_tokens(&self, out: &mut TokenStream) -> Result<(), Self::BadIdent>
(Try to) convert to tokens (ie, real Ident)
Depending on the implementor, this might be fallible, or not.
Provided Methods§
Sourcefn note_atoms(&self, out: &mut Vec<AtomForReport>)
fn note_atoms(&self, out: &mut Vec<AtomForReport>)
Transfer information about the atoms in this IdentFrag into out
If, ultimately, a bad identifier is constructed using some of this input, these atoms will be reported.