domacro

Crates.iodomacro
lib.rsdomacro
version0.1.0
created_at2025-11-12 02:03:16.83334+00
updated_at2025-11-12 02:03:16.83334+00
descriptionProc macro to invoke a macro providing a function as input
homepage
repositoryhttps://github.com/chancehudson/anondb.git
max_upload_size
id1928666
size3,976
Chance (chancehudson)

documentation

README

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>();
            }
        }
    };
}
Commit count: 0

cargo fmt