refactor: replace private trait with free fn (dead-code warning); CLI smoke ok
This commit is contained in:
@@ -252,7 +252,7 @@ impl Decoder {
|
||||
let p0 = self.dco0_periods_fs[address as usize] as i64;
|
||||
let p1 = self.dco1_periods_fs[address as usize] as i64;
|
||||
let correction = ((cnt0 as i64 - 1) * p0) - ((cnt1 as i64 - 1) * p1);
|
||||
let asic_timestamp = base.saturating_sub_signed(correction);
|
||||
let asic_timestamp = saturating_sub_signed(base, correction);
|
||||
|
||||
let (ix, iy) = decode_position(address);
|
||||
let timestamp = 10u64
|
||||
@@ -297,17 +297,11 @@ impl Default for Decoder {
|
||||
|
||||
/// Saturating subtraction of a signed correction from an unsigned base
|
||||
/// (the C wraps in uint64; here we saturate at 0 — never-crash rule).
|
||||
trait SaturatingSubSigned {
|
||||
fn saturating_sub_signed(self, rhs: i64) -> u64;
|
||||
}
|
||||
|
||||
impl SaturatingSubSigned for u64 {
|
||||
fn saturating_sub_signed(self, rhs: i64) -> u64 {
|
||||
if rhs >= 0 {
|
||||
self.saturating_sub(rhs as u64)
|
||||
} else {
|
||||
self.saturating_add(rhs.unsigned_abs())
|
||||
}
|
||||
fn saturating_sub_signed(base: u64, correction: i64) -> u64 {
|
||||
if correction >= 0 {
|
||||
base.saturating_sub(correction as u64)
|
||||
} else {
|
||||
base.saturating_add(correction.unsigned_abs())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user