Trait IdentExt
trait IdentExt: Sized + private::Sealed
Additional methods for Ident not provided by proc-macro2 or libproc_macro.
This trait is sealed and cannot be implemented for types outside of Syn. It
is implemented only for proc_macro2::Ident.
Required Methods
fn parse_any(input: ParseStream<'_>) -> Result<Self>Parses any identifier including keywords.
This is useful when parsing macro input which allows Rust keywords as identifiers.
Example
use ; use IdentExt; use ParseStream; // Parses input that looks like `name = NAME` where `NAME` can be // any identifier. // // Examples: // // name = anything // name = implfn unraw(self: &Self) -> IdentStrips the raw marker
r#, if any, from the beginning of an ident.- unraw(
x) =x - unraw(
move) =move - unraw(
r#move) =move
Example
In the case of interop with other languages like Python that have a different set of keywords than Rust, we might come across macro input that involves raw identifiers to refer to ordinary variables in the other language with a name that happens to be a Rust keyword.
The function below appends an identifier from the caller's input onto a fixed prefix. Without using
unraw(), this would tend to produce invalid identifiers like__pyo3_get_r#move.use Span; use Ident; use IdentExt;- unraw(
Implementors
impl IdentExt for proc_macro2::Ident