From ec818828f54deb4cd0be665bd90f6a601567b173 Mon Sep 17 00:00:00 2001 From: nicoo Date: Sun, 4 Oct 2020 15:05:46 +0200 Subject: [PATCH] SampleRate: Implement std::ops::{Div, Mul} Closes #482 --- src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 06df8ac3e..bd21f475e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -159,6 +159,7 @@ pub use platform::{ }; pub use samples_formats::{Sample, SampleFormat}; use std::convert::TryInto; +use std::ops::{Div, Mul}; use std::time::Duration; mod error; @@ -180,6 +181,26 @@ pub type ChannelCount = u16; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub struct SampleRate(pub u32); +impl Mul for SampleRate +where + u32: Mul, +{ + type Output = Self; + fn mul(self, rhs: T) -> Self { + SampleRate(self.0 * rhs) + } +} + +impl Div for SampleRate +where + u32: Div, +{ + type Output = Self; + fn div(self, rhs: T) -> Self { + SampleRate(self.0 / rhs) + } +} + /// The desired number of frames for the hardware buffer. pub type FrameCount = u32;