Skip to content

Instantly share code, notes, and snippets.

@XMPPwocky
Created October 24, 2014 04:09
Show Gist options
  • Save XMPPwocky/c5c618d8e18401b81325 to your computer and use it in GitHub Desktop.
Save XMPPwocky/c5c618d8e18401b81325 to your computer and use it in GitHub Desktop.
pub fn apply_update<Component, MarshalledComponent, UpdatesIter: Iterator<ComponentUpdate<MarshalledComponent>>>(
mut updates: UpdatesIter,
hdict: &mut HashMap<RawComponentHandle, ComponentHandle<Component>>,
store: &mut ComponentStore<Component>,
unmarshaller: |MarshalledComponent, ComponentHandle<Component>| -> Component,
inserter: |MarshalledComponent, &mut ComponentStore<Component>| -> ComponentHandle<Component>)
{
for update in updates {
match update.data {
Change(comp) => match hdict.find_copy(&update.target) {
Some(handle) => {
*store.find_mut(handle).unwrap() = unmarshaller(comp, handle);
},
None => {
hdict.insert(update.target, inserter(comp, store));
}
},
Destroy => match hdict.find_copy(&update.target) {
Some(handle) => {store.remove(handle);},
None => () // weeeird.
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment