A bunch more work on replacing every potential panic with results
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-16 19:57:21 +02:00
parent 1b8403ecda
commit 00d596d656
37 changed files with 526 additions and 300 deletions

View File

@@ -1,3 +1,4 @@
use anyhow_ext::Result;
use std::sync::Arc;
use indexmap::IndexMap;
@@ -48,8 +49,11 @@ pub trait DataLibrary<T: ?Sized> {
}
/// Gets a random value from the library.
fn random_value(&self, rand: &mut Random) -> &Arc<T> {
fn random_value(&self, rand: &mut Random) -> Result<&Arc<T>> {
let i = rand.get_between(0, self.len() as i32);
return self.map().get_index(i as usize).unwrap().1;
match self.map().get_index(i as usize) {
Some(v) => Ok(v.1),
None => anyhow::bail!("No value found for index {}", i),
}
}
}