I do Rust, implementing matrix math, and I come across several snags. I identified features that I thought were relevant to the matrix.
trait Matrix<T> where T : num::Num { fn dim(&self) -> (usize, usize); fn elem(&self, i : usize, j : usize) -> Option<& T>; fn new_const(v: T, rows : usize, cols : usize) -> Self where T : Clone; fn same_dim<U>(&self, other: &U) -> bool where U : Matrix<T> { self.dim() == other.dim() } }
I have a dumb implementation using Vec<Vec<T>> . I implemented all the methods and tested them. They all work. Now I just want to add two matrices together. Therefore, without adding the row iterator, which, as I know, will be required, and performing the implementation of the addition, which, as I know, will be incorrect, I added the following.
impl <T, U> Add for U where T: num::Num, U: Matrix<T> { type Output = U; fn add(self, _rhs: U) -> U { U::new_const(T::zero(), 5, 5) } }
but i get
lib.rs:41:7: 41:8 error: the type parameter `T` is not constrained by the impl trait, self type, or predicates [E0207] lib.rs:41 impl <T, U> Add for U where T: num::Num, U: Matrix<T> { ^ lib.rs:41:7: 41:8 help: run `rustc --explain E0207` to see a detailed explanation error: aborting due to previous error Could not compile `matrix`. To learn more, run the command again with --verbose. Compilation failed.
T seems to me limited. Can someone point me in the right direction?