有没有办法在不需要AddAssign
orClone
的情况下编写这个函数T
?
use std::ops::Add;
fn increment<T: Add<isize, Output = T>>(x: &mut T) {
*x = *x + 1;
}
如所写,我收到错误:
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