I am struggling to define e.g. std::ops::Add for my generic type ( Custom say) where i want to be able to add e.g. a f64 both from the left and the right.
I.e I would like:
let c: Custom<T> = ...;
let a = 1.0;
return a + c + a;
to work - but cannot see how to implement that. See for example Rust Playground for a simplified example of what does not work.
a + b is syntactic sugar for A::add(a, b), so b + a always calls the add() method on B. Thus, you'd have to blanket-impl Add<Custom<T>> for T, but that isn't allowed due to coherence.
Note that this doesn't require the above impl! Addition associates to the left, so if <A as Add<C>>::Output = A, then this will work with the above unilateral impl andimpl Add<Custom<T>> for Custom<T>: Playground.