Skip to content

Instantly share code, notes, and snippets.

@killercup
Forked from anonymous/playground.rs
Created September 30, 2015 12:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save killercup/8f21ec5c2eae07762143 to your computer and use it in GitHub Desktop.
Save killercup/8f21ec5c2eae07762143 to your computer and use it in GitHub Desktop.
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
Copy link

fschutt commented Jun 30, 2017

thanks

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