I was about to say "you can't do it", but I think you can -- the trick is to use a bounded generic implementation. Once "Mul" becomes a trait, you'll be able to say this:
trait MatrixMultiplyRHS<Result> {
fn mul(matrix: Matrix) -> Result;
}
impl<RHS:MatrixMultiplyRHS<Result>,Result> Matrix : Mul<RHS, Result> {
fn mul(rhs: RHS) -> Result {
rhs.mul(self)
}
}
impl float : MatrixMultiplyRHS<Matrix> {
fn mul(matrix: Matrix) -> Matrix {
// ...implementation of matrix scalar multiply...
}
}
impl Vector : MatrixMultiplyRHS<Vector> {
fn mul(matrix: Matrix) -> Vector {
// ... implementation of matrix multiply for vectors ...
}
}
impl Matrix : MatrixMultiplyRHS<Matrix> {
fn mul(matrix: Matrix) -> Matrix {
// ... implementation of matrix multiply for matrices ...
}
}
It's admittedly a bit awkward, but maybe that's OK to discourage overloading unless you actually need it. Still, your point was very interesting -- I didn't realize this was possible! -- and I'll spread it around the team.