identity-macro 0.1.0

Remove metavariable fragment to make it reusable for macro_rules
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented2 out of 3 items with examples
  • Size
  • Source code size: 5.14 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 122.76 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • A4-Tacks/identity-macro-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • A4-Tacks

Remove metavariable fragment to make it reusable for macro_rules

Resetting span of Group will subtly forget that Group comes from metavariable

Example

Compile failed case:

macro_rules! foo {
    (1+2) => {};
}
macro_rules! bar {
    ($e:expr) => {
        foo!($e)
    };
}
bar!(1+2);

Use identity macro:

use identity_macro::identity;

macro_rules! foo {
    (1+2) => {};
}
macro_rules! bar {
    ($e:expr) => {
        identity!(foo!($e))
    };
}
bar!(1+2);

After matching with objects like $e:expr, the content will be wrapped in a Group(Delimiter::None), and marked with fragments using span related methods to prevent it from being matched by different fragments

This crate utilizes the fragment information lost when setting the span to enable it to be re matched

NOTE: macro_rules will automatically flatten Group(Delimiter::None) without fragments, so there is no need to manually unpack them, but it is also not possible to use tt to pass the entire Group