Loads of work to replace panics with results.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
use anyhow::Result;
|
||||
use std::sync::atomic::{AtomicU8, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -80,7 +81,7 @@ impl LearnedMove {
|
||||
}
|
||||
|
||||
/// Restore the remaining PP by a certain amount. Will prevent it from going above max PP.
|
||||
pub fn restore_uses(&self, mut uses: u8) {
|
||||
pub fn restore_uses(&self, mut uses: u8) -> Result<()> {
|
||||
self.remaining_pp
|
||||
.fetch_update(Ordering::SeqCst, Ordering::SeqCst, |x| {
|
||||
if x + uses > self.max_pp {
|
||||
@@ -88,7 +89,8 @@ impl LearnedMove {
|
||||
}
|
||||
Some(x + uses)
|
||||
})
|
||||
.unwrap();
|
||||
.ok();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +112,7 @@ mod tests {
|
||||
let data: Arc<dyn MoveData> = Arc::new(mock);
|
||||
let learned_move = LearnedMove::new(data, MoveLearnMethod::Level);
|
||||
assert!(learned_move.try_use(15));
|
||||
learned_move.restore_uses(5);
|
||||
learned_move.restore_uses(5).unwrap();
|
||||
assert_eq!(20, learned_move.remaining_pp());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user