I’m going to create topics containing error codes and messages such that, by title, they are easy to find by others too.
The purpose of such topics would be gathering other examples of code giving the error and solutions to them.
The description of the error: https://doc.rust-lang.org/error-index.html#E0502. The solution provided there does not seem to fit my bill.
The first sample code is at https://gist.github.com/flavius/353e633c6758b565dbc902c7632092ef/cf31965f6c51830e7f5d454a114e5d157abc4517
src/lib.rs:85:20: 85:23 error: cannot borrow `log` as immutable because it is also borrowed as mutable [E0502] src/lib.rs:85 assert_eq!(log.version(), entry.version()); ^~~ src/lib.rs:84:21: 84:24 note: mutable borrow occurs here src/lib.rs:84 let entry = log.new_entry(); ^~~ src/lib.rs:86:5: 86:6 note: mutable borrow ends here src/lib.rs:86 } ^ src/lib.rs:85:9: 85:52 note: in this expansion of assert_eq! (defined in <std macros>) src/lib.rs:85:20: 85:23 help: run `rustc --explain E0502` to see a detailed explanation
How to solve this problem? The
AppendlogEntry newly created needs to stay owned by the vector