I just found a usage for the `*&` idiom

138 points afdbcreid

ndarray (and probably nalgebra too, but I haven't checked) provides operators, including in-place operators, but the problem is that in-place operators must be applied to assignable LHS, and assignable LHSes do not include method calls. So this, for example, does not compile:

arr.column_mut(1) += 1;

You can solve this by importing std::ops::AddAssign and doing:

arr.column_mut(1).add_assign(1);

But this loses the nicety of the operator.

Today I thought that because dereferenced place is an assignable LHS, we can do this weird thing:

*&mut arr.column_mut(1) += 1;

Playground.