Skip to content

Instantly share code, notes, and snippets.

@fengsp
Created October 4, 2014 06:02
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 fengsp/e683bc864cf5cf8cfcd0 to your computer and use it in GitHub Desktop.
Save fengsp/e683bc864cf5cf8cfcd0 to your computer and use it in GitHub Desktop.
Rust generic and trait
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