Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. extern crate num_traits;
  2. use num_traits::Num;
  3. use num::cast::AsPrimitive;
  4.  
  5. fn my_fn<T>(t: T, t2: i8) -> u32
  6. where T: Num + PartialEq + Copy + 'static,
  7. i8: AsPrimitive<T>,
  8. {
  9. if t == t2.as_() {
  10. 0
  11. } else {
  12. 3
  13. }
  14. }
  15.  
  16. #[test]
  17. fn test_t() {
  18. let t: u32 = 32;
  19. assert_eq!(my_fn(t, 3), 3);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement