Created
January 22, 2018 12:23
-
-
Save anonymous/ac152997e17242b81daf32dbeae49950 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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