Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Rust min! and max! macros
macro_rules! max {
($x:expr) => ( $x );
($x:expr, $($xs:expr),+) => {
{
use std::cmp::max;
max($x, max!( $($xs),+ ))
}
};
}
macro_rules! min {
($x:expr) => ( $x );
($x:expr, $($xs:expr),+) => {
{
use std::cmp::min;
min($x, min!( $($xs),+ ))
}
};
}
fn main() {
println!("{:?}", max!(2, 5, 9, -42, 5));
println!("{:?}", min!(2, 5, 9, -42, 5));
}
@fschutt

This comment has been minimized.

Copy link

@fschutt fschutt commented Jun 30, 2017

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment