Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. use num::{Float, Integer};
  2.  
  3. macro_rules! declare_trait {
  4. ($trait_type:ident,$trait_name:ident) => {
  5. trait $trait_name:
  6. $trait_type
  7. + num::FromPrimitive
  8. + num::ToPrimitive
  9. + alga::general::RealField
  10. + std::marker::Copy
  11. + std::clone::Clone
  12. + std::fmt::Debug
  13. + 'static
  14. {
  15. }
  16.  
  17. impl<T> $trait_name for T where
  18. T: $trait_type
  19. + num::FromPrimitive
  20. + num::ToPrimitive
  21. + alga::general::RealField
  22. + std::marker::Copy
  23. + std::clone::Clone
  24. + std::fmt::Debug
  25. + 'static
  26. {
  27. }
  28. };
  29. }
  30.  
  31. declare_trait!(Float, NumericFloatTrait);
  32. declare_trait!(Integer, NumericIntTrait);
  33.  
  34. struct SomeStruct;
  35.  
  36. impl SomeStruct {
  37. fn do_things_with_float<T: NumericFloatTrait>(num: T) {
  38. println!("I got this float {:?}", num);
  39. }
  40.  
  41. fn do_things_with_int<T: NumericIntTrait>(num: T) {
  42. println!("I got this int {:?}", num);
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement