Hi
I’m trying to port some code to Rust to learn the language and hitting a wall here. Would appreciate any advice.
Here’s what I’m trying to do.
I have a struct State that represents a global mutable state (does not need to be thread-safe) of the system and also contains a vector of components each having it’s own state.
I’m trying to write a funciton that would update the global state and the state of each component.
The minimal version looks like this
struct Component;
impl Component {
fn update(&mut self, _state: &mut State) { }
}
struct State {
components: Vec<Component>
}
impl State {
fn update(&mut self) {
// update self
for component in self.components.iter_mut() {
component.update(self);
}
}
}
Is there any way to make it work?
Appreciate this is probalby not the most idiomatic way, my plan was to first port the orignal code (from java) as close as possible and then refactor it.
Thanks.