Skip to main content

Crate token_metadata

Crate token_metadata 

Source
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 of TokenTreeWithMetadatas.

Structs§

GroupWithMetadata
A version of Group with arbitrary attached metadata. The tokens within this GroupWithMetadata also have metadata.
TokenWithMetadata
A simple struct holding a token and its associated metadata.

Enums§

TokenTreeWithMetadata
A version of TokenTree with arbitrary attached metadata.

Type Aliases§

TokenWithMetadataVec
A type alias for a Vec of TokenTreeWithMetadatas.