4 ms·
> Blech! Having to explicitly borrow temporary values is super gross. I don’t think you ever have to write code like this. Implement your math traits in terms
by arcticbull 4y ago
> Blech! Having to explicitly borrow temporary values is super gross.
I don’t think you ever have to write code like this. Implement your math traits in terms for both value and reference types like the standard library does.
Go down to Trait Implementations for scalar types, for instance i32 [1]
impl Add<&i32> for &i32
impl Add<&i32> for i32
impl Add<i32> for &i32
impl Add<i32> for i32
Once you do that your ergonomics should be exactly the same as with built in scalar types.
[1] https://doc.rust-lang.org/std/primitive.i32.html https://doc.rust-lang.org/std/primitive.i32.html