domacro 0.1.0

Proc macro to invoke a macro providing a function as input
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 3.97 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 268.91 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • chancehudson

domacro

Pass the name of a function to a macro for arbitrary expansion. Does not break IDE/auto-complete/syntax highlighting for the function in question!

Example use

If I have a trait with multiple implementations, I want to write a generic test function and invoke it for all implementations of the trait.

use domacro::domacro;

trait WorkerTrait {
  fn works(&self) -> bool;
}

#[domacro(all_impls)]
fn test<T: WorkerTrait>(instance: T) {
  assert!(instance.works());
}

#[macro_export]
macro_rules! all_impls {
    ($fn_name:ident) => {
        paste::paste! {
            #[test]
            fn [<aliceworker_ $fn_name>]() {
                $fn_name::<AliceWorker>();
            }

            #[test]
            fn [<bobworker_ $fn_name>]() {
                $fn_name::<BobWorker>();
            }

            #[test]
            fn [<zuluworker_ $fn_name>]() {
                $fn_name::<ZuluWorker>();
            }
        }
    };
}