proclet 0.3.0

Proc macros made easy
Documentation
  • Coverage
  • 100%
    308 out of 308 items documented1 out of 3 items with examples
  • Size
  • Source code size: 157.63 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 42.32 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • maia-s/proclet
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • maia-s

proclet: proc macros made easy

⚠️ proclet is still in early development. It's missing some basic features and may get major design changes, and documentation is a work in progress.

proclet can be used with either proc-macro or proc-macro2, or both. Most of the types of the proc-macro crates are abstracted into traits, and proclet's types are generic over these traits. If you run into type inference issues, there's proc-macro specific aliases for the proclet types in the pm1 and pm2 modules.

Here's how you'd make a proc macro that takes a set of comma separated strings as arguments (last comma optional):

#[proc_macro]
pub fn my_proc_macro(input: TokenStream) -> TokenStream {
    proclet(input, |input| {
        let args = punctuated(StringLiteral::parser(), op(",")).parse_all(input)?;
        // ...
    })
}

The proclet function is an optional wrapper that converts the input to a TokenBuf ready for parsing, converts the output back into a TokenStream, and handles errors by making them nice spanned compiler errors instead of panics.

parse_all returns an error if there's tokens left in the buffer after parsing. To leave the rest of the buffer for the next parser to parse, use the parse method instead.

You can combine parsers to parse more complex objects like punctuated does in the example above. Types that implement the Parse trait can be parsed directly:

let string = StringLiteral::parse(input)?;

The input is automatically advanced to point past the parsed object on success.