aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2021-04-26 20:04:06 +0200
committerAndreas Grois <andi@grois.info>2021-04-26 20:04:06 +0200
commit94a8deabd176c07fbf825627cbbbdb3b95b85b15 (patch)
treea665229f00adfafc2f41bde4153223ec9c5a2572
parent9ca86c6211a29b22e82823171f2b0831f2ab0177 (diff)
New clippy lints, better code...
-rw-r--r--clock/src/lib.rs14
-rw-r--r--swaystatus-plugin/src/lib.rs18
-rw-r--r--swaystatus/src/communication/mod.rs4
-rw-r--r--testconfig2
4 files changed, 25 insertions, 13 deletions
diff --git a/clock/src/lib.rs b/clock/src/lib.rs
index 3fa1b97..109045b 100644
--- a/clock/src/lib.rs
+++ b/clock/src/lib.rs
@@ -81,7 +81,7 @@ impl<'c> SwayStatusModuleRunnable for ClockRunnable<'c> {
ClockRefreshRate::NotSynchronized { seconds } => {
self.simple_loop(std::time::Duration::from_secs_f32(seconds.abs()));
},
- ClockRefreshRate::UTCSynchronized { updates_per_thirty_minutes }=> {
+ ClockRefreshRate::UtcSynchronized { updates_per_thirty_minutes }=> {
self.synchronized_loop(std::cmp::max(updates_per_thirty_minutes,1) as u64);
}
}
@@ -112,7 +112,7 @@ enum ClockRefreshRate {
#[serde(rename = "Seconds")]
seconds : f32
},
- UTCSynchronized {
+ UtcSynchronized {
#[serde(rename = "PerThirtyMinutes")]
updates_per_thirty_minutes : u16
}
@@ -129,7 +129,7 @@ impl Default for ClockConfig {
fn default() -> Self {
ClockConfig {
format : String::from("%R"),
- refresh_rate : ClockRefreshRate::UTCSynchronized { updates_per_thirty_minutes: 1800 }
+ refresh_rate : ClockRefreshRate::UtcSynchronized { updates_per_thirty_minutes: 1800 }
}
}
}
@@ -175,11 +175,11 @@ enum MessagesFromMain {
struct SenderForMain(Sender<MessagesFromMain>);
impl MsgMainToModule for SenderForMain {
- fn send_quit(&self) -> Result<(),()> {
- self.0.send(MessagesFromMain::Quit).map_err(|_| ())
+ fn send_quit(&self) -> Result<(),PluginCommunicationError> {
+ self.0.send(MessagesFromMain::Quit).map_err(|_| PluginCommunicationError)
}
- fn send_refresh(&self) -> Result<(),()> {
- self.0.send(MessagesFromMain::Refresh).map_err(|_| ())
+ fn send_refresh(&self) -> Result<(),PluginCommunicationError> {
+ self.0.send(MessagesFromMain::Refresh).map_err(|_| PluginCommunicationError)
}
}
diff --git a/swaystatus-plugin/src/lib.rs b/swaystatus-plugin/src/lib.rs
index 3e27d19..1d2d22b 100644
--- a/swaystatus-plugin/src/lib.rs
+++ b/swaystatus-plugin/src/lib.rs
@@ -77,13 +77,13 @@ pub trait MsgMainToModule {
/// Implement this in such a way, that when it's called from the main thread, your module will
/// soon-ish return from it's main function, after cleaning up it's resources and after joining
/// all threads it spawns.
- fn send_quit(&self) -> Result<(),()>;
+ fn send_quit(&self) -> Result<(),PluginCommunicationError>;
/// Implement this in such a way, that when it's called from the main thread, your module will
/// soon-ish send an updated text. The main module does not really wait for updates, so
/// ignoring this or implementing it empty is perfectly fine if you know that your module's
/// output cannot possibly change between updates it sends anyhow.
- fn send_refresh(&self) -> Result<(),()>;
+ fn send_refresh(&self) -> Result<(),PluginCommunicationError>;
}
/// When communicating an error to the main program, this allows to choose an appropriate handling
@@ -124,7 +124,7 @@ pub trait MsgModuleToMain : Send {
/// stdout output. While this can in theory return an error, that should practically never
/// happen. If this errors, you should probably clean up your resources and return from the
/// run() function. In other words, act as if main had sent you a quit command.
- fn send_update(&self, text : Result<String, PluginError>) -> Result<(),()>;
+ fn send_update(&self, text : Result<String, PluginError>) -> Result<(),PluginCommunicationError>;
}
/// Interface your module should implement. All functions of this will be called in the main thread.
@@ -161,3 +161,15 @@ pub trait SwayStatusModuleInstance : erased_serde::Serialize {
fn make_runnable<'p>(&'p self, to_main : Box<dyn MsgModuleToMain + 'p>) -> (Box<dyn SwayStatusModuleRunnable + 'p>, Box<dyn MsgMainToModule + 'p>);
}
serialize_trait_object!(SwayStatusModuleInstance);
+
+///Error type used by send functions.
+#[derive(Debug)]
+pub struct PluginCommunicationError;
+
+impl std::fmt::Display for PluginCommunicationError {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(f,"Communication between plugin and main program terminated unexpectedly")
+ }
+}
+
+impl std::error::Error for PluginCommunicationError {}
diff --git a/swaystatus/src/communication/mod.rs b/swaystatus/src/communication/mod.rs
index c0deff9..ff4a5ce 100644
--- a/swaystatus/src/communication/mod.rs
+++ b/swaystatus/src/communication/mod.rs
@@ -46,8 +46,8 @@ impl Drop for SenderToMain {
}
impl plugin::MsgModuleToMain for SenderToMain {
- fn send_update(&self, text : Result<String, plugin::PluginError>) -> Result<(),()> {
+ fn send_update(&self, text : Result<String, plugin::PluginError>) -> Result<(),plugin::PluginCommunicationError> {
let message = Message::External { text , element_number : self.element_number };
- self.sender.send(message).map_err(|_| {})
+ self.sender.send(message).map_err(|_| plugin::PluginCommunicationError)
}
}
diff --git a/testconfig b/testconfig
index 3e0768b..89c9dcf 100644
--- a/testconfig
+++ b/testconfig
@@ -8,5 +8,5 @@ Plugin = "ClockPlugin"
Format = "%+"
[Element.Config.RefreshRate]
-Synchronization = "UTCSynchronized"
+Synchronization = "UtcSynchronized"
PerThirtyMinutes = 1800