Closed jedbrown closed 9 months ago
This is a good idea. I think anything that works with floats and that we can support should be supported, so I'd like to add this.
Done in #53. Your example:
let velocity = [Velocity::meters_per_second(5.0); 3];
let energy = 0.5 * velocity.iter().map(|v| v * v).sum::<SpecificEnergy>();
now compiles.
Wonderful, thanks!
In various circumstances, including with iterators such as below, you're holding a reference and would like to perform arithmetic.
This works in Diman if one writes the closure as
|v| *v * *v
, but the above works with nondimensional types and is less visually noisy. Should arithmetic (Add
,Sub
,Mul
,Div
) be implemented for all four combinations in which one or both of the args are references?Yes, this case also works with
|v| v.powi::<2>()
.