A Rust attribute for parameterizing generic functions
Find a file
Andrew Cassidy 775649937d
Some checks failed
Build and Release / build (push) Failing after 1m12s
Dont try to update rustup
2025-11-01 19:35:20 -07:00
.github/workflows Dont try to update rustup 2025-11-01 19:35:20 -07:00
src Update documentation 2024-06-16 12:51:02 -07:00
tests Support function argument parameterization 2024-06-16 12:39:46 -07:00
.gitignore initial commit 2022-08-10 19:53:06 -07:00
Cargo.toml Update source URL 2025-10-26 06:05:18 +00:00
CHANGELOG.md Release 0.3.0 2024-06-16 12:51:32 -07:00
LICENSE.md License as MPL-2.0 2022-08-14 16:38:17 -07:00
README.md Add Readme 2022-08-14 17:30:43 -07:00

Generic Parameterize

This crate provides the parameterize macro, which allow parameterizing generic functions for applications like unit testing.

for example,

use generic_parameterize::parameterize;
use std::fmt::Debug;

#[parameterize(T = (i32, f32), N = [4, 5, 6])]
#[test]
fn test_array<T: Default, const N: usize>() where [T; N]: Default + Debug {
    let foo: [T; N] = Default::default();
    println!("{:?}", foo)
}

generates a module called test_array containing functions called test_array_i32_4, test_array_i32_5 etc. The #[test] attribute gets copied to the child functions, which in turn call a copy of test_array. The result looks like:

mod test_array {
    use std::println;
    fn test_array<T: Default, const N : usize>() where [T;N]: Default + std::fmt::Debug{
         let foo: [T;N] = Default::default();
         println!("{:?}", foo)
    }

    #[test]
    fn test_array_i32_4() {test_array::<i32,4>();}
    #[test]
    fn test_array_f32_4() {test_array::<f32,4>();}
    #[test]
    fn test_array_i32_5() {test_array::<i32,5>();}
    // etc...
 }