I would like to implement a commutative scalar multiplication operation f64using an operator *. Implementing a trait Mul<f64>for my type gives me the correct multiplication, for example.
struct Foo(f64);
impl Mul<f64> for Foo {
type Output = Foo;
fn mul(self, _rhs: f64) -> Foo {
}
}
let a = Foo(1.23);
a * 3.45;
3.45 * a;
For a scalar type that is not built-in, you can implement the same attribute on the contrary in a scalar, i.e. implementing Mul<Foo>on my scalar type.
How to get left implementation for inline type, for example f64?
source
share