Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use num::{Float, Integer};
- macro_rules! declare_trait {
- ($trait_type:ident,$trait_name:ident) => {
- trait $trait_name:
- $trait_type
- + num::FromPrimitive
- + num::ToPrimitive
- + alga::general::RealField
- + std::marker::Copy
- + std::clone::Clone
- + std::fmt::Debug
- + 'static
- {
- }
- impl<T> $trait_name for T where
- T: $trait_type
- + num::FromPrimitive
- + num::ToPrimitive
- + alga::general::RealField
- + std::marker::Copy
- + std::clone::Clone
- + std::fmt::Debug
- + 'static
- {
- }
- };
- }
- declare_trait!(Float, NumericFloatTrait);
- declare_trait!(Integer, NumericIntTrait);
- struct SomeStruct;
- impl SomeStruct {
- fn do_things_with_float<T: NumericFloatTrait>(num: T) {
- println!("I got this float {:?}", num);
- }
- fn do_things_with_int<T: NumericIntTrait>(num: T) {
- println!("I got this int {:?}", num);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement