Skip to content

dwhensley/precond

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

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

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages