Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Precond

Toy repo to explore Rust procedural macros. Annotate functions with the precond attribute macro to execute a transformation on input arguments.

use precond::precond;

#[precond(|a, b| if b == 0 { (b, a) } else { (a, b) })]
fn gcd(a: i64, b: i64) -> (i64, i64, i64) {
    // -- snip --
}

#[precond(|a, b| (std::cmp::min(a, 100), std::cmp::min(b, 100)))]
fn clipped_add(a: u8, b: u8) -> u8 {
    a + b
}

To run the tests:

cargo test 

To take a look at the test code after macro expansion, you can install cargo-expand (needs a nightly compiler):

cargo install cargo-expand

And emit the expanded test code:

cargo expand --test precond

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages