token-metadata 0.1.0

Data structures to associate arbitrary metadata with [`proc_macro2`] tokens.
Documentation
  • Coverage
  • 100%
    34 out of 34 items documented0 out of 21 items with examples
  • Size
  • Source code size: 19.65 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.03 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Aseminaunz/token-metadata
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Aseminaunz

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.