-
-
Save piedoom/2524485cf58603c524f006b7724d72bc to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub struct MyStruct<'a> { | |
stuffs: Vec<&'a AnotherStruct> | |
} | |
pub struct AnotherStruct { | |
some_data: DataStruct | |
} | |
pub struct DataStruct { | |
number: i32, | |
another_number: i32, | |
yet_another_number: i32, | |
is_cool: bool | |
} | |
impl<'a> MyStruct<'a> { | |
pub fn do_something(&self, data: DataStruct) { | |
for stuff in &self.stuffs { | |
if stuff.some_data.is_cool == data.is_cool{ | |
stuff.some_data = data; // <============== cannot mutably borrow immutable field | |
break; | |
} | |
} | |
} | |
} | |
fn main(){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment