Created
October 24, 2014 04:09
-
-
Save XMPPwocky/d51c20a344869ba20f7c to your computer and use it in GitHub Desktop.
This file contains 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 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