From 9f5ce597e3c2c727264502b2e870f36882c41925 Mon Sep 17 00:00:00 2001 From: tdittr Date: Sun, 21 Feb 2021 12:42:05 +0100 Subject: [PATCH] Implement mul for generic rate Mul is already implemented for the fixed point variants of rate. This is useful when calculating rates after a PLL. --- src/rate.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/rate.rs b/src/rate.rs index b855c6b..0819989 100644 --- a/src/rate.rs +++ b/src/rate.rs @@ -13,6 +13,7 @@ pub use fixed_point::FixedPoint as _; use num::{CheckedDiv, CheckedMul}; #[doc(inline)] pub use units::*; +use core::ops::Mul; /// An unsigned, fixed-point rate type /// @@ -370,6 +371,17 @@ impl Generic { impl Rate for Generic {} +impl Mul for Generic { + type Output = Generic; + + fn mul(self, rhs: T) -> Self::Output { + Self { + integer: self.integer * rhs, + scaling_factor: self.scaling_factor, + } + } +} + /// Rate-type units #[doc(hidden)] pub mod units {