From 17e079d15d66dff39ca9457d77f70534ef755adc Mon Sep 17 00:00:00 2001 From: Darakshan Farber Date: Tue, 21 Jul 2020 12:54:49 -0700 Subject: [PATCH 1/2] Eliminate or suppress Clippy messages. --- build.rs | 2 +- src/host/coreaudio/enumerate.rs | 4 ++-- src/host/coreaudio/mod.rs | 21 ++++++++++++++------- src/lib.rs | 3 ++- src/samples_formats.rs | 8 ++++---- 5 files changed, 23 insertions(+), 15 deletions(-) diff --git a/build.rs b/build.rs index c6382cc..5e2a54e 100644 --- a/build.rs +++ b/build.rs @@ -6,7 +6,7 @@ fn main() { // If ASIO directory isn't set silently return early // otherwise set the asio config flag match env::var(CPAL_ASIO_DIR) { - Err(_) => return, + Err(_) => {}, Ok(_) => println!("cargo:rustc-cfg=asio"), }; } diff --git a/src/host/coreaudio/enumerate.rs b/src/host/coreaudio/enumerate.rs index bdfd5d0..7ba8e38 100644 --- a/src/host/coreaudio/enumerate.rs +++ b/src/host/coreaudio/enumerate.rs @@ -109,7 +109,7 @@ pub fn default_input_device() -> Option { } let device = Device { - audio_device_id: audio_device_id, + audio_device_id, }; Some(device) } @@ -138,7 +138,7 @@ pub fn default_output_device() -> Option { } let device = Device { - audio_device_id: audio_device_id, + audio_device_id, }; Some(device) } diff --git a/src/host/coreaudio/mod.rs b/src/host/coreaudio/mod.rs index eb74a96..f947462 100644 --- a/src/host/coreaudio/mod.rs +++ b/src/host/coreaudio/mod.rs @@ -160,7 +160,7 @@ impl Device { check_os_status(status)?; let c_string: *const c_char = CFStringGetCStringPtr(device_name, kCFStringEncodingUTF8); - if c_string == null() { + if c_string.is_null() { let status = AudioObjectGetPropertyData( self.audio_device_id, &property_address as *const _, @@ -192,6 +192,7 @@ impl Device { } // Logic re-used between `supported_input_configs` and `supported_output_configs`. + #[allow(clippy::cast_ptr_alignment)] fn supported_configs( &self, scope: AudioObjectPropertyScope, @@ -289,7 +290,7 @@ impl Device { min_sample_rate: SampleRate(range.mMinimum as _), max_sample_rate: SampleRate(range.mMaximum as _), buffer_size: buffer_size.clone(), - sample_format: sample_format, + sample_format, }; fmts.push(fmt); } @@ -386,8 +387,8 @@ impl Device { let config = SupportedStreamConfig { sample_rate: SampleRate(asbd.mSampleRate as _), channels: asbd.mChannelsPerFrame as _, - buffer_size: buffer_size, - sample_format: sample_format, + buffer_size, + sample_format, }; Ok(config) } @@ -470,7 +471,7 @@ fn asbd_from_config( SampleFormat::F32 => (kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked) as u32, _ => kAudioFormatFlagIsPacked as u32, }; - let asbd = AudioStreamBasicDescription { + AudioStreamBasicDescription { mBitsPerChannel: bits_per_channel as _, mBytesPerFrame: bytes_per_frame as _, mChannelsPerFrame: n_channels as _, @@ -480,8 +481,7 @@ fn asbd_from_config( mFormatID: kAudioFormatLinearPCM, mSampleRate: sample_rate as _, ..Default::default() - }; - asbd + } } fn audio_unit_from_device(device: &Device, input: bool) -> Result { @@ -528,6 +528,9 @@ fn audio_unit_from_device(device: &Device, input: bool) -> Result( &self, config: &StreamConfig, @@ -656,6 +659,10 @@ impl Device { // Wait for the reported_rate to change. // // This should not take longer than a few ms, but we timeout after 1 sec just in case. + // + // WARNING: a reference to reported_rate is unsafely captured above, + // and the loop below assumes it can change - but compiler does not know that! + // let timer = ::std::time::Instant::now(); while sample_rate != reported_rate { if timer.elapsed() > Duration::from_secs(1) { diff --git a/src/lib.rs b/src/lib.rs index 246e821..dab37ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -423,6 +423,7 @@ impl OutputCallbackInfo { } } +#[allow(clippy::len_without_is_empty)] impl Data { // Internal constructor for host implementations to use. // @@ -457,7 +458,7 @@ impl Data { pub fn len(&self) -> usize { self.len } - + /// The raw slice of memory representing the underlying audio data as a slice of bytes. /// /// It is up to the user to interpret the slice of memory based on `Data::sample_format`. diff --git a/src/samples_formats.rs b/src/samples_formats.rs index cd146e4..faa0231 100644 --- a/src/samples_formats.rs +++ b/src/samples_formats.rs @@ -15,10 +15,10 @@ impl SampleFormat { /// Returns the size in bytes of a sample of this format. #[inline] pub fn sample_size(&self) -> usize { - match self { - &SampleFormat::I16 => mem::size_of::(), - &SampleFormat::U16 => mem::size_of::(), - &SampleFormat::F32 => mem::size_of::(), + match *self { + SampleFormat::I16 => mem::size_of::(), + SampleFormat::U16 => mem::size_of::(), + SampleFormat::F32 => mem::size_of::(), } } } From 7d35b7d44894f11b5564003a808cabc9b10dd303 Mon Sep 17 00:00:00 2001 From: Darakshan Farber Date: Tue, 21 Jul 2020 17:59:53 -0700 Subject: [PATCH 2/2] rustfmt --- build.rs | 2 +- src/host/coreaudio/enumerate.rs | 8 ++------ src/lib.rs | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/build.rs b/build.rs index 5e2a54e..52cddc5 100644 --- a/build.rs +++ b/build.rs @@ -6,7 +6,7 @@ fn main() { // If ASIO directory isn't set silently return early // otherwise set the asio config flag match env::var(CPAL_ASIO_DIR) { - Err(_) => {}, + Err(_) => {} Ok(_) => println!("cargo:rustc-cfg=asio"), }; } diff --git a/src/host/coreaudio/enumerate.rs b/src/host/coreaudio/enumerate.rs index 7ba8e38..f7b3e78 100644 --- a/src/host/coreaudio/enumerate.rs +++ b/src/host/coreaudio/enumerate.rs @@ -108,9 +108,7 @@ pub fn default_input_device() -> Option { return None; } - let device = Device { - audio_device_id, - }; + let device = Device { audio_device_id }; Some(device) } @@ -137,9 +135,7 @@ pub fn default_output_device() -> Option { return None; } - let device = Device { - audio_device_id, - }; + let device = Device { audio_device_id }; Some(device) } diff --git a/src/lib.rs b/src/lib.rs index dab37ba..7cf2851 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -458,7 +458,7 @@ impl Data { pub fn len(&self) -> usize { self.len } - + /// The raw slice of memory representing the underlying audio data as a slice of bytes. /// /// It is up to the user to interpret the slice of memory based on `Data::sample_format`.