SampleRate: Implement std::ops::{Div, Mul}

Closes #482
This commit is contained in:
nicoo 2020-10-04 15:05:46 +02:00
parent 2b31fe41af
commit ec818828f5
No known key found for this signature in database
GPG key ID: E6F98EE292D5ECCB

View file

@ -159,6 +159,7 @@ pub use platform::{
}; };
pub use samples_formats::{Sample, SampleFormat}; pub use samples_formats::{Sample, SampleFormat};
use std::convert::TryInto; use std::convert::TryInto;
use std::ops::{Div, Mul};
use std::time::Duration; use std::time::Duration;
mod error; mod error;
@ -180,6 +181,26 @@ pub type ChannelCount = u16;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct SampleRate(pub u32); pub struct SampleRate(pub u32);
impl<T> Mul<T> for SampleRate
where
u32: Mul<T, Output = u32>,
{
type Output = Self;
fn mul(self, rhs: T) -> Self {
SampleRate(self.0 * rhs)
}
}
impl<T> Div<T> for SampleRate
where
u32: Div<T, Output = u32>,
{
type Output = Self;
fn div(self, rhs: T) -> Self {
SampleRate(self.0 / rhs)
}
}
/// The desired number of frames for the hardware buffer. /// The desired number of frames for the hardware buffer.
pub type FrameCount = u32; pub type FrameCount = u32;