Add a next_key() method to primary entity maps.

It is sometimes useful to know the entity reference number that will be
assigned to the next thing added to a map.
This commit is contained in:
Jakob Stoklund Olesen
2016-09-13 16:14:46 -07:00
parent 4fd15f98ed
commit 525c69bbe8

View File

@@ -94,9 +94,14 @@ impl<K, V> EntityMap<K, V>
where K: EntityRef,
V: PrimaryEntityData
{
/// Get the key that will be assigned to the next pushed value.
pub fn next_key(&self) -> K {
K::new(self.elems.len())
}
/// Append `v` to the mapping, assigning a new key which is returned.
pub fn push(&mut self, v: V) -> K {
let k = K::new(self.elems.len());
let k = self.next_key();
self.elems.push(v);
k
}