From 6277f4351fd68f1cdd434818eac7b0d18eac3c76 Mon Sep 17 00:00:00 2001 From: Andreas Grois Date: Mon, 29 Nov 2021 22:38:44 +0100 Subject: Run clippy and fix all lints. --- pulse/src/communication.rs | 2 +- pulse/src/config.rs | 12 +++++------- pulse/src/runnable/pulse.rs | 35 +++++++++++++++-------------------- 3 files changed, 21 insertions(+), 28 deletions(-) (limited to 'pulse/src') diff --git a/pulse/src/communication.rs b/pulse/src/communication.rs index 51456d9..ce31875 100644 --- a/pulse/src/communication.rs +++ b/pulse/src/communication.rs @@ -21,7 +21,7 @@ impl<'p> SenderForMain { } fn send(&self, message : MessagesFromMain) -> Result<(), PluginCommunicationError> { - if let Ok(_) = self.sender.send(message) { + if self.sender.send(message).is_ok() { //The cool thing about pulse using poll() is that poll() also wakes up if started after //the actual wake up call. So no need to worry about races, this is inherently sane! self.pulse_waker.as_ref().ok_or(PluginCommunicationError {})?.wake_up()?; diff --git a/pulse/src/config.rs b/pulse/src/config.rs index f95bd46..0be7367 100644 --- a/pulse/src/config.rs +++ b/pulse/src/config.rs @@ -128,7 +128,7 @@ impl Default for PulseVolumeConfig { impl SwayStatusModuleInstance for PulseVolumeConfig { fn make_runnable<'p>(&'p self,to_main : Box) -> (Box, Box) { - let (runnable, sender_for_main) = crate::runnable::PulseVolumeRunnable::new(&self, to_main); + let (runnable, sender_for_main) = crate::runnable::PulseVolumeRunnable::new(self, to_main); (Box::new(runnable), Box::new(sender_for_main)) } } @@ -162,13 +162,11 @@ impl FormatableVolume String { diff --git a/pulse/src/runnable/pulse.rs b/pulse/src/runnable/pulse.rs index 2f8398a..32d31e6 100644 --- a/pulse/src/runnable/pulse.rs +++ b/pulse/src/runnable/pulse.rs @@ -47,30 +47,28 @@ impl<'c> PulseContext<'c> { if api.is_null() { Err(PulseContextCreationError::FailedToGetPulseApi) } - else { - if let Ok(plugin_name) = CString::new("Swaystatus Pulse Plugin") { - let context = unsafe { pa_context_new(api, plugin_name.as_ptr()) }; - if context.is_null() { - Err(PulseContextCreationError::ContextNewFailed) - } - else { - Ok(PulseContext { context, scratch, main : pulse}) - } + else if let Ok(plugin_name) = CString::new("Swaystatus Pulse Plugin") { + let context = unsafe { pa_context_new(api, plugin_name.as_ptr()) }; + if context.is_null() { + Err(PulseContextCreationError::ContextNewFailed) } else { - Err(PulseContextCreationError::SettingNameFailed) + Ok(PulseContext { context, scratch, main : pulse}) } } + else { + Err(PulseContextCreationError::SettingNameFailed) + } } pub(super) fn iterate(&mut self, relevant_sink : &Option) -> Result { self.scratch.sink_we_care_about = relevant_sink.clone(); self.scratch.volume = None; self.scratch.default_sink = None; self.main.main_loop.iterate()?; - return Ok(IterationResult { + Ok(IterationResult { default_sink : self.scratch.default_sink.clone(), volume : self.scratch.volume.clone() - }); + }) } pub(super) fn get_state(&self) -> PaContextState { unsafe { pa_context_get_state(self.context) } @@ -98,12 +96,9 @@ impl<'c> PulseContext<'c> { extern "C" fn on_context_state_change(context : *mut PaContext, scratch : *mut c_void) { unsafe { - match pa_context_get_state(context) { - PaContextState::Ready => { - pa_context_set_subscribe_callback(context,Some(Self::on_context_event),scratch); - pa_operation_unref(pa_context_subscribe(context,0x80 /* SERVER */ | 0x01 /* SINK */, None, std::ptr::null_mut())); - } - _ => {} + if let PaContextState::Ready = pa_context_get_state(context) { + pa_context_set_subscribe_callback(context,Some(Self::on_context_event),scratch); + pa_operation_unref(pa_context_subscribe(context,0x80 /* SERVER */ | 0x01 /* SINK */, None, std::ptr::null_mut())); } } } @@ -121,7 +116,7 @@ impl<'c> PulseContext<'c> { pa_operation_unref(pa_context_get_server_info(context,Some(Self::on_server_info_received),scratch as *mut c_void)); } _ /* should not happen */ => { - assert!(false); + unreachable!(); } } } @@ -424,7 +419,7 @@ impl PulseOperation { Cancelled } -#[allow(dead_code)] //this is partially dead code, but the unused enum values are kept for readability reasons. +#[allow(dead_code, clippy::enum_variant_names)] //this is partially dead code, but the unused enum values are kept for readability reasons. Also, clippy is over-zealous here. #[repr(C)] enum PaContextFlags { NoFlags = 0, NoAutoSpawn = 1, -- cgit v1.2.3