Modifying two *different* elements of a vector in one function?
⚓ Rust 📅 2025-10-09 👤 surdeus 👁️ 5Is there any way to modify two separate elements of a vector in a single scope? The borrow checker is not happy with my code. I am not sure how to procede. Do I have to wrap things with RefCell? Do I wrap each element of the vector in RefCell -- eg a vector of RefCells, each wrapping the inner struct, and then calling borrow_mut on elements as needed. Or is there another option?
The code I am working on is on github: GitHub - RobertPHeller/time_table: Model Railroad Time Table generating program and the problem function is in src/lib.rs, is TimeTableSystem::UpdateTrainStorageAtStop starting at line 985.
3 posts - 2 participants
🏷️ Rust_feed