Mastodon Feed: Post

Mastodon Feed

rust@mas.to ("Rust tips") wrote:

`&mut` references are exclusive and non-copyable¹.

When they're a field of a struct like an Iterator, you'll get `&'call mut &'field mut`, which usually limits *both* to `'call`'s lifetime.

Modifying the field's reference is going to need `std::mem::take` to operate on the only instance of the reference.

https://quinedot.github.io/rust-learning/lt-ex-mut-slice.html

¹) #RustLang can "re-borrow" them to make a new `&mut` loan, but it's not a copy, because it must have a shorter lifetime and makes the source temporarily unusable.