| Crates.io | token-metadata |
| lib.rs | token-metadata |
| version | 0.1.0 |
| created_at | 2025-11-15 04:39:55.002942+00 |
| updated_at | 2025-11-15 04:39:55.002942+00 |
| description | Data structures to associate arbitrary metadata with [`proc_macro2`] tokens. |
| homepage | |
| repository | https://github.com/aseminaunz/token-metadata |
| max_upload_size | |
| id | 1934012 |
| size | 19,654 |
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 [Vec]s of [TokenTreeWithMetadata]s. 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.