Skip to content

vmihdal/proc-macro-ctx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust proc macro with shared context

Example of how Rust proc macros could have a shared context, so every macro crate is using the same metadata no matter in which order macros are expanded.

Structure

  • ctx - Defines common context, logic for generating metadata from source code and functions to store / load metadata
  • example - Binary that uses our macros
  • macros - Example of macros that use shared metadata

How it works

The ctx crate analyzes the code of dependant crate example during execution of its build.rs and generates metadata into build directory. The macros crate uses ctx functionality to load metadata for the example crate during proc macro expanding stage and generates some code using loaded information.

How to use it

  • Execute cargo run to run it.
  • Execute cargo expand -p example to see how generated code.

About

Example of Rust proc macro with shared context

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages