Expand description
§Token Metadata
This library provides data structures to associate arbitrary metadata with proc_macro2 tokens.
Using this library, you can create tokens that carry additional information alongside them, and use them in a manner similar to proc_macro2’s. This may be useful for code analysis, transformation, escaping, hygiene, or whichever other purpose may suit your needs.
The main type provided, TokenTreeWithMetadata, is a wrapper over TokenTree, which allows attaching metadata of any type to any individual token.
Similarly, GroupWithMetadata is a re-implementation of Group where the tokens also have their own metadata.
For storing collections of tokens with metadata, use Vecs of TokenTreeWithMetadatas. An alias is provided as TokenWithMetadataVec. token_with_metadata_iter_ext provides utility functions for working with iterators of tokens with metadata (e.g, TokenStream).
You can convert from tokens with metadata to ordinary tokens with the strip_metadata methods provided (They are not automatically implemented via From to avoid accidental data loss). If your metadata has a Default value, implementations of From are provided to create tokens with metadata from ordinary tokens. Otherwise, you can construct them as you would any other struct or enum.
This library is no_std, and only depends on proc-macro2 and alloc.
Modules§
- token_
with_ metadata_ iter_ ext - Extension module for
TokenWithMetadataVec, or more generally, for iterators ofTokenTreeWithMetadatas.
Structs§
- Group
With Metadata - A version of
Groupwith arbitrary attached metadata. The tokens within thisGroupWithMetadataalso have metadata. - Token
With Metadata - A simple struct holding a token and its associated metadata.
Enums§
- Token
Tree With Metadata - A version of
TokenTreewith arbitrary attached metadata.
Type Aliases§
- Token
With Metadata Vec - A type alias for a
VecofTokenTreeWithMetadatas.