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. --- clock/src/lib.rs | 2 +- pulse/src/communication.rs | 2 +- pulse/src/config.rs | 12 +++++------- pulse/src/runnable/pulse.rs | 35 +++++++++++++++-------------------- swaystatus/src/main.rs | 4 ++-- 5 files changed, 24 insertions(+), 31 deletions(-) diff --git a/clock/src/lib.rs b/clock/src/lib.rs index adde06e..74c1241 100644 --- a/clock/src/lib.rs +++ b/clock/src/lib.rs @@ -138,7 +138,7 @@ impl SwayStatusModuleInstance for ClockConfig { fn make_runnable<'p>(&'p self, to_main : Box) -> (Box, Box) { let (sender_from_main, from_main) = channel(); let runnable = ClockRunnable { - config : &self, + config : self, from_main, to_main }; 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, diff --git a/swaystatus/src/main.rs b/swaystatus/src/main.rs index 09320f5..f476131 100644 --- a/swaystatus/src/main.rs +++ b/swaystatus/src/main.rs @@ -104,11 +104,11 @@ fn core_loop(plugin_path : &std::path::Path, config_path : &std::path::Path) -> forward_to_all_plugins(&senders_to_plugins,&elements, i); }, communication::Message::External{text, element_number} => { - handle_message_from_element(&mut texts, &elements[element_number].get_name(), element_number, text); + handle_message_from_element(&mut texts, elements[element_number].get_name(), element_number, text); print_texts(&texts, &main_config, &elements); }, communication::Message::ThreadCrash{element_number} => { - handle_crash_from_element(&mut texts, &elements[element_number].get_name(), element_number); + handle_crash_from_element(&mut texts, elements[element_number].get_name(), element_number); print_texts(&texts, &main_config, &elements); } } -- cgit v1.2.3