diff --git a/crates/innesco-decoding/src/lib.rs b/crates/innesco-decoding/src/lib.rs index 3be230c..212cbae 100644 --- a/crates/innesco-decoding/src/lib.rs +++ b/crates/innesco-decoding/src/lib.rs @@ -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()) } }