Add trait for saturating arithmetic (#15812)

* Add SaturatingArithmetic trait

* Use Duration saturating arithmetic

* Use new macro to fix poh_config
This commit is contained in:
Tyera Eulberg
2021-03-11 23:22:40 -07:00
committed by GitHub
parent cc38ae72e7
commit e5b644e830
4 changed files with 61 additions and 11 deletions

View File

@@ -1,5 +1,4 @@
#![allow(clippy::integer_arithmetic)]
use crate::clock::DEFAULT_TICKS_PER_SECOND;
use crate::{clock::DEFAULT_TICKS_PER_SECOND, unchecked_div_by_const};
use std::time::Duration;
#[derive(Serialize, Deserialize, Clone, Debug, AbiExample)]
@@ -29,8 +28,9 @@ impl PohConfig {
impl Default for PohConfig {
fn default() -> Self {
Self::new_sleep(Duration::from_micros(
1000 * 1000 / DEFAULT_TICKS_PER_SECOND,
))
Self::new_sleep(Duration::from_micros(unchecked_div_by_const!(
1000 * 1000,
DEFAULT_TICKS_PER_SECOND
)))
}
}