Unexpected borrow checker errors when implementing a trait for a struct with a Vec in Rust
I keep running into I've been banging my head against this for hours..... I'm having trouble implementing a trait for my struct that contains a `Vec`... My struct looks like this: ```rust struct MyStruct { data: Vec<i32>, } impl MyStruct { fn new() -> Self { MyStruct { data: Vec::new() } } } ``` Now, I want to implement a trait called `Process` that requires a method to process the elements of the `Vec`. The trait is defined like this: ```rust trait Process { fn process(&self) -> i32; } ``` I tried to implement it like this: ```rust impl Process for MyStruct { fn process(&self) -> i32 { self.data.iter().sum() } } ``` However, I'm getting a borrow checker behavior that says: ``` behavior[E0502]: want to borrow `self.data` as immutable because it is also borrowed as mutable ``` I don't understand why this is happening since I'm not mutably borrowing `data` in the `process` method. I've checked the rest of my code, and I don't have any mutable references to `self` when calling `process`. I even tried to clone the data, but that feels inefficient and Iād rather avoid unnecessary allocations if possible. Iām using Rust version 1.64, and I would appreciate any insight into why this borrow checker behavior is occurring and how I can resolve it without compromising performance. Am I missing something in my implementation or perhaps in how Iām managing the lifetimes of my references? What am I doing wrong? This is for a REST API running on Linux. Is there a better approach? The project is a mobile app built with Rust. Thanks for any help you can provide!