A bunch more work on replacing every potential panic with results
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user