Make SupportedStreamConfigRange fields private

This commit is contained in:
mitchmindtree 2020-02-02 20:08:46 +01:00
parent 9bf5664f7d
commit 7a6cb0bd6a
1 changed files with 33 additions and 4 deletions

View File

@ -191,13 +191,13 @@ pub struct StreamConfig {
/// `Device::supported_input/output_configs` method. /// `Device::supported_input/output_configs` method.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub struct SupportedStreamConfigRange { pub struct SupportedStreamConfigRange {
pub channels: ChannelCount, pub(crate) channels: ChannelCount,
/// Minimum value for the samples rate of the supported formats. /// Minimum value for the samples rate of the supported formats.
pub min_sample_rate: SampleRate, pub(crate) min_sample_rate: SampleRate,
/// Maximum value for the samples rate of the supported formats. /// Maximum value for the samples rate of the supported formats.
pub max_sample_rate: SampleRate, pub(crate) max_sample_rate: SampleRate,
/// Type of data expected by the device. /// Type of data expected by the device.
pub sample_format: SampleFormat, pub(crate) sample_format: SampleFormat,
} }
/// Describes a single supported stream configuration, retrieved via either a /// Describes a single supported stream configuration, retrieved via either a
@ -335,6 +335,35 @@ impl Data {
} }
impl SupportedStreamConfigRange { impl SupportedStreamConfigRange {
pub fn channels(&self) -> ChannelCount {
self.channels
}
pub fn min_sample_rate(&self) -> SampleRate {
self.min_sample_rate
}
pub fn max_sample_rate(&self) -> SampleRate {
self.max_sample_rate
}
pub fn sample_format(&self) -> SampleFormat {
self.sample_format
}
/// Retrieve a `SupportedStreamConfig` with the given sample rate.
///
/// **panic!**s if the given `sample_rate` is outside the range specified within this
/// `SupportedStreamConfigRange` instance.
pub fn with_sample_rate(self, sample_rate: SampleRate) -> SupportedStreamConfig {
assert!(sample_rate <= self.min_sample_rate && sample_rate <= self.max_sample_rate);
SupportedStreamConfig {
channels: self.channels,
sample_format: self.sample_format,
sample_rate,
}
}
/// Turns this `SupportedStreamConfigRange` into a `SupportedStreamConfig` corresponding to the maximum samples rate. /// Turns this `SupportedStreamConfigRange` into a `SupportedStreamConfig` corresponding to the maximum samples rate.
#[inline] #[inline]
pub fn with_max_sample_rate(self) -> SupportedStreamConfig { pub fn with_max_sample_rate(self) -> SupportedStreamConfig {