Is there a way to write this function without requiring AddAssign
or Clone
on T
?
use std::ops::Add;
fn increment<T: Add<isize, Output = T>>(x: &mut T) {
*x = *x + 1;
}
As written, I get the error:
error[E0507]: cannot move out of `*x` which is behind a mutable reference
--> src/lib.rs:4:10
|
4 | *x = *x + 1;
| ^^ move occurs because `*x` has type `T`, which does not implement the `Copy` trait