Advertisement
cwchen

[Rust] Using generics in functions

Sep 8th, 2017
917
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.16 KB | None | 0 0
  1. // For a trait of general number
  2. extern crate num;
  3.  
  4. fn add<T>(a: T, b: T) -> T where T: num::Num {
  5.     a + b
  6. }
  7.  
  8. fn main() {
  9.     assert_eq!(5, add(3, 2));
  10. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement