You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
replace can be annoying to use as one liner because of the borrow checker, a good solution is to swap arguments order:
fnmain(){letmut i = 0;assert_eq!(0, replace(i + 1, &mut i));assert_eq!(1, std::mem::replace(&mut i, i + 1));assert_eq!(2, i);}fnreplace<T>(src:T,dest:&mutT) -> T{
core::mem::replace(dest, src)}
rror[E0503]: cannot use `i` because it was mutably borrowed
--> src/main.rs:5:45
|
5 | assert_eq!(1, std::mem::replace(&mut i, i + 1));
| ----------------- ------ ^ use of borrowed `i`
| | |
| | borrow of `i` occurs here
| borrow later used by call
Unfortunately, in my knowledge even Rust edition can't allow this breaking change, I see potential solution:
add a new function in mem module (what name ? replace2() ?)
breaking change somehow
do nothing and live with it
The text was updated successfully, but these errors were encountered:
replace
can be annoying to use as one liner because of the borrow checker, a good solution is to swap arguments order:Unfortunately, in my knowledge even Rust edition can't allow this breaking change, I see potential solution:
replace2()
?)The text was updated successfully, but these errors were encountered: