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:
@@ -94,9 +94,14 @@ impl<K, V> EntityMap<K, V>
|
|||||||
where K: EntityRef,
|
where K: EntityRef,
|
||||||
V: PrimaryEntityData
|
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.
|
/// Append `v` to the mapping, assigning a new key which is returned.
|
||||||
pub fn push(&mut self, v: V) -> K {
|
pub fn push(&mut self, v: V) -> K {
|
||||||
let k = K::new(self.elems.len());
|
let k = self.next_key();
|
||||||
self.elems.push(v);
|
self.elems.push(v);
|
||||||
k
|
k
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user