Skip to content

Instantly share code, notes, and snippets.

Created January 22, 2018 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/ac152997e17242b81daf32dbeae49950 to your computer and use it in GitHub Desktop.
Save anonymous/ac152997e17242b81daf32dbeae49950 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
// function that returns the bigger of the two numbers. the type output type
// should be the bigger of LHS or RHS
fn maximum<LHS, RHS, Output>(lhs: LHS, rhs: RHS) -> Output
where
LHS: Copy,
RHS: Copy,
Output: PartialOrd + Copy + From<RHS> + From<LHS>,
{
let lhs = lhs.into();
let rhs = rhs.into();
if lhs > rhs {
lhs
} else {
rhs
}
}
fn main() {
println!("{}", maximum::<u8, u16, u16>(4u8, 99u16));
println!("{}", maximum::<u16, u8, u16>(3242u16, 23u8));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment