token-metadata

Crates.iotoken-metadata
lib.rstoken-metadata
version0.1.0
created_at2025-11-15 04:39:55.002942+00
updated_at2025-11-15 04:39:55.002942+00
descriptionData structures to associate arbitrary metadata with [`proc_macro2`] tokens.
homepage
repositoryhttps://github.com/aseminaunz/token-metadata
max_upload_size
id1934012
size19,654
Aimar Seminario (Aseminaunz)

documentation

README

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 [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.

Commit count: 0

cargo fmt