Skip to content

Instantly share code, notes, and snippets.

@bstrie
Created May 23, 2015 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bstrie/cd5583c96f3745918f72 to your computer and use it in GitHub Desktop.
Save bstrie/cd5583c96f3745918f72 to your computer and use it in GitHub Desktop.
src\scene.rs:54:30: 54:34 error: cannot borrow `*self` as mutable more than once at a time
src\scene.rs:54 let sprite = self.child_mut(id).unwrap();
^~~~
src\scene.rs:54:30: 54:34 note: previous borrow of `*self` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `*self
` until the borrow ends
src\scene.rs:54 let sprite = self.child_mut(id).unwrap();
^~~~
src\scene.rs:81:6: 81:6 note: previous borrow ends here
src\scene.rs:40 pub fn event<E>(&'a mut self, e: &E) where E: GenericEvent {
...
src\scene.rs:81 }
^
src\scene.rs:78:17: 78:29 error: cannot borrow `self.running` as mutable more than once at a time
src\scene.rs:78 self.running.insert(id, new_animations);
^~~~~~~~~~~~
src\scene.rs:54:30: 54:34 note: previous borrow of `*self` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `*self
` until the borrow ends
src\scene.rs:54 let sprite = self.child_mut(id).unwrap();
^~~~
src\scene.rs:81:6: 81:6 note: previous borrow ends here
src\scene.rs:40 pub fn event<E>(&'a mut self, e: &E) where E: GenericEvent {
...
src\scene.rs:81 }
^
error: aborting due to 2 previous errors
Could not compile `piston2d-sprite`.
pub fn event<E>(&'a mut self, e: &E) where E: GenericEvent {
// regenerate the animations and their states
let running = self.running.clone();
self.running.clear();
for (id, animations) in running.into_iter() {
let mut new_animations = Vec::new();
for (b, mut a, paused) in animations.into_iter() {
if paused {
new_animations.push((b, a, paused));
continue;
}
let sprite = self.child_mut(id).unwrap();
let (status, _) = a.event(e, &mut |_, dt, animation, s| {
let (state, status, remain) = {
let start_state;
let state = match *s {
None => { start_state = animation.to_state(sprite); &start_state },
Some(ref state) => state,
};
state.update(sprite, dt)
};
*s = state;
(status, remain)
});
match status {
// the behavior is still running, add it for next update
Running => {
new_animations.push((b, a, paused));
},
_ => {},
}
}
if new_animations.len() > 0 {
self.running.insert(id, new_animations);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment