Created
October 4, 2014 06:02
-
-
Save fengsp/e683bc864cf5cf8cfcd0 to your computer and use it in GitHub Desktop.
Rust generic and trait
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
fn main() { | |
println!("Hello, world!") | |
println!("{}", add(1i, 2i)) | |
println!("{}", add(1.0f64, 2.0f64)) | |
} | |
fn add<T: Add<T, T>>(x :T, y: T) -> T{ | |
x + y | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment