Skip to content

Commit 6923d72

Browse files
committed
Associated types
1 parent cdd580b commit 6923d72

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/types.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11

2-
use num_complex::Complex;
2+
pub use num_complex::Complex32 as c32;
3+
pub use num_complex::Complex64 as c64;
4+
use num_traits::Float;
5+
use std::ops::*;
36

4-
pub use num_comlex::Complex32 as c32;
5-
pub use num_comlex::Complex64 as c64;
7+
pub trait AssociatedReal: Sized {
8+
type Real: Float + Mul<Self, Output = Self>;
9+
}
10+
pub trait AssociatedComplex: Sized {
11+
type Complex;
12+
}
13+
14+
macro_rules! impl_assoc {
15+
($real:ty, $complex:ty) => {
16+
impl AssociatedReal for $real {
17+
type Real = $real;
18+
}
19+
impl AssociatedReal for $complex {
20+
type Real = $real;
21+
}
22+
impl AssociatedComplex for $real {
23+
type Complex = $complex;
24+
}
25+
impl AssociatedComplex for $complex {
26+
type Complex = $complex;
27+
}
28+
}} // impl_assoc!
29+
30+
impl_assoc!(f64, c64);
31+
impl_assoc!(f32, c32);

0 commit comments

Comments
 (0)