sort-macro 0.2.0

Sort macro input tokens
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented2 out of 2 items with examples
  • Size
  • Source code size: 7.07 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 252.83 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • A4-Tacks/sort-macro-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • A4-Tacks
sort-macro-0.2.0 has been yanked.

Sort macro input tokens

Example

After sorting, it is easy to input keys in an unordered manner

macro_rules! foo {
    (@branch (a $a:literal) (b $b:literal)) => {
        concat!(stringify!($a), stringify!($b))
    };
    ($($name:ident : $val:literal)+) => {
        sort_macro::sort_in!([.0] {@branch} foo!($( ($name $val) )+))
    };
}
fn main() {
    assert_eq!(foo!(b:3 a:2), "23");
    assert_eq!(foo!(a:2 b:3), "23");
}

Grammar

Sort in last group, sort key is TokenTree::to_string

input  = [key] [prefix] *tt group
prefix = "{" *tt "}"
key    = "[" *tt "]"

The key grammar reference: https://github.com/A4-Tacks/tt-path-rs