Quite often, I see the following pattern.
It would be safe for the compiler to accept this but the borrow checker is unhappy.
In a nutshell, a struct’s method requires borrowing self mutably.
The result borrows self but immutably. The borrow checker extends the mutable borrow to the lifetime of the result.
The example here seem contrived, but I met this in real life.
For instance, in the
fst crate (a finite state transducer crate. If you are unfamiliar with FST, it would be the same with a trie) ,
.next() modifies a buffer containing the and returning a reference to that buffer.
- Will this example be solved by NLL?
- Has it bothered other people?
- Is there a way to workaround it simply?