mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-24 23:15:24 +03:00
Fix a crash with the new FixedMap. Don't assume the keys exist!
This commit is contained in:
parent
ad41303e5c
commit
357ac4e549
@ -282,19 +282,22 @@ impl<K: IndexableKey, V> FixedMap<K, V> {
|
||||
}
|
||||
|
||||
pub fn get(&self, key: &K) -> Option<&V> {
|
||||
self.inner[key.index()].as_ref()
|
||||
self.inner.get(key.index())?.as_ref()
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, key: &K) -> Option<&mut V> {
|
||||
self.inner[key.index()].as_mut()
|
||||
self.inner.get_mut(key.index())?.as_mut()
|
||||
}
|
||||
|
||||
pub fn contains_key(&self, key: &K) -> bool {
|
||||
self.inner[key.index()].is_some()
|
||||
self.inner
|
||||
.get(key.index())
|
||||
.map(|x| x.is_some())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn remove(&mut self, key: &K) -> Option<V> {
|
||||
self.inner[key.index()].take()
|
||||
self.inner.get_mut(key.index())?.take()
|
||||
}
|
||||
|
||||
pub fn values(&self) -> std::iter::Flatten<std::slice::Iter<'_, std::option::Option<V>>> {
|
||||
|
Loading…
Reference in New Issue
Block a user