6 files changed, 45 insertions(+), 43 deletions(-)

M src/bin/brightctl.rs
M src/bin/brightd.rs
M src/cli.rs
M src/dbus.rs
M src/lib.rs
M src/pond.rs
M src/bin/brightctl.rs +6 -6
@@ 59,7 59,7 @@ impl AppConfig {
             other => panic!("Subcommand match not handled: {:?}", other),
         };
         let devices: Vec<String> = match matches.values_of("devices") {
-            Some(names) => names.map(|n| String::from(n)).collect(),
+            Some(names) => names.map(String::from).collect(),
             None => Vec::new(),
         };
         let bustype = match matches.value_of("bustype") {

          
@@ 76,9 76,9 @@ impl AppConfig {
             None => None,
         };
         Ok(AppConfig {
-            action: action,
-            devices: devices,
-            bustype: bustype,
+            action,
+            devices,
+            bustype,
             minimum: min,
         })
     }

          
@@ 125,7 125,7 @@ fn get_brightness_dbus(cfg: &AppConfig) 
     let client = dbus_client(&cfg.bustype)?;
     for objpath in client.devices()?.iter() {
         let name = client.name(objpath.to_owned())?;
-        if cfg.devices.len() > 0 && !cfg.devices.contains(&name) {
+        if !cfg.devices.is_empty() && !cfg.devices.contains(&name) {
             continue;
         }
         let val = client.get(objpath.to_owned())?;

          
@@ 157,7 157,7 @@ fn set_brightness_dbus(cfg: &AppConfig) 
     let client = dbus_client(&cfg.bustype)?;
     for objpath in client.devices()?.iter() {
         let name = client.name(objpath.to_owned())?;
-        if cfg.devices.len() > 0 && !cfg.devices.contains(&name) {
+        if !cfg.devices.is_empty() && !cfg.devices.contains(&name) {
             continue;
         }
         match cfg.action {

          
M src/bin/brightd.rs +5 -5
@@ 53,7 53,7 @@ fn run_acpi_listener(cfg: AppConfig, bus
     info!("Listening for ACPI events on {}", cfg.acpi_socket.display());
     let stream = UnixStream::connect(cfg.acpi_socket)?;
     let buffer = std::io::BufReader::new(stream);
-    for bytes in buffer.split('\n' as u8) {
+    for bytes in buffer.split(b'\n') {
         let bytes = bytes?;
         if bytes.starts_with(b"video/brightnessup BRTUP") {
             for dev in client.devices()?.iter() {

          
@@ 71,7 71,7 @@ fn run_acpi_listener(cfg: AppConfig, bus
 
 fn run_dbus_svc(cfg: AppConfig, busname_tx: mpsc::Sender<String>) -> Result<(), failure::Error> {
     let devices = bright::create_devices(Vec::new())?;
-    let mut dbus_svc = match bright::dbus::DBusService::new(cfg.bustype, Rc::new(devices.clone())) {
+    let mut dbus_svc = match bright::dbus::DBusService::new(cfg.bustype, Rc::new(devices)) {
         Ok(svc) => svc,
         Err(err) => {
             error!("{}", err);

          
@@ 84,8 84,8 @@ fn run_dbus_svc(cfg: AppConfig, busname_
     let delay = match watchdog {
         0 => std::time::Duration::new(2, 0),
         us => {
-            let secs = (us / 2) / 1000_000;
-            let nsec = ((us / 2) % 1000_000) * 1000;
+            let secs = (us / 2) / 1_000_000;
+            let nsec = ((us / 2) % 1_000_000) * 1000;
             std::time::Duration::new(secs, nsec as u32)
         }
     };

          
@@ 170,7 170,7 @@ impl AppConfig {
         let acpi_step = matches.value_of("acpi-step").unwrap();
         let acpi_min = matches.value_of("acpi-min").unwrap();
         Ok(AppConfig {
-            bustype: bustype,
+            bustype,
             acpi: matches.is_present("acpi"),
             acpi_socket: std::path::PathBuf::from(acpi_socket),
             acpi_step: acpi_step.trim().parse::<u32>().unwrap(),

          
M src/cli.rs +1 -1
@@ 81,7 81,7 @@ only modify one or more devices use the 
 fn is_int(arg: String) -> Result<(), String> {
     match arg.trim().parse::<u32>() {
         Ok(_) => Ok(()),
-        Err(_) => Err(String::from(format!("Not a positive integer: {}", arg))),
+        Err(_) => Err(format!("Not a positive integer: {}", arg)),
     }
 }
 

          
M src/dbus.rs +20 -27
@@ 28,7 28,6 @@ 
 //    /be/devork/dbus/bright/devices/<name>, however you should only
 //    ever acquire these object paths from the manager.
 
-use std;
 use std::collections::HashMap;
 use std::rc::Rc;
 use std::sync::Arc;

          
@@ 39,10 38,10 @@ use failure_derive::Fail;
 use log::{debug, error, info};
 
 // The public DBus names we use.
-pub static BUSNAME: &'static str = "be.devork.dbus.bright";
-pub static MANAGER_PATH: &'static str = "/be/devork/dbus/bright/manager";
-pub static MANAGER_IFACE: &'static str = "be.devork.dbus.bright.Manager";
-pub static DEVICE_IFACE: &'static str = "be.devork.dbus.bright.BacklightDevice";
+pub static BUSNAME: &str = "be.devork.dbus.bright";
+pub static MANAGER_PATH: &str = "/be/devork/dbus/bright/manager";
+pub static MANAGER_IFACE: &str = "be.devork.dbus.bright.Manager";
+pub static DEVICE_IFACE: &str = "be.devork.dbus.bright.BacklightDevice";
 
 // The public interface.
 #[derive(Debug)]

          
@@ 73,12 72,12 @@ impl DBusService {
         let devices_iface = Arc::new(iface_backlight_device(Rc::clone(&connection), state_tx));
         let mut svc = DBusService {
             busname: String::from(BUSNAME),
-            devices: devices,
-            devices_iface: devices_iface,
+            devices,
+            devices_iface,
             states: HashMap::new(),
-            state_rx: state_rx,
-            connection: connection,
-            term_rx: term_rx,
+            state_rx,
+            connection,
+            term_rx,
         };
         debug!("Intialising devices...");
         for device in svc.devices.iter() {

          
@@ 148,9 147,8 @@ impl DBusService {
         while start.elapsed() < timeout {
             let remaining = timeout
                 .checked_sub(start.elapsed())
-                .unwrap_or(std::time::Duration::new(0, 0));
-            let remaining_ms =
-                remaining.as_secs() * 1000 + ((remaining.subsec_nanos() / 1000000) as u64);
+                .unwrap_or_else(|| std::time::Duration::new(0, 0));
+            let remaining_ms = remaining.as_secs() * 1000 + (remaining.subsec_millis() as u64);
             self.incoming(remaining_ms as u32)?.next();
             match self.term_rx.try_recv() {
                 Ok(_val) => {

          
@@ 481,15 479,10 @@ fn signal_brightness_changes(
             }
         });
     }
-    loop {
-        match sigs.pop() {
-            Some(prop) => {
-                use crate::dbus::dbus::SignalArgs;
-                let msg = prop.to_emit_message(path);
-                conn.send(msg).unwrap_or(0);
-            }
-            None => break,
-        }
+    while let Some(prop) = sigs.pop() {
+        use crate::dbus::dbus::SignalArgs;
+        let msg = prop.to_emit_message(path);
+        conn.send(msg).unwrap_or(0);
     }
     Ok(())
 }

          
@@ 525,7 518,7 @@ impl<'a> Client<'a> {
         self.conn
             .send(msg)
             .and(Ok(()))
-            .or_else(|_| Err(failure::err_msg("Failed sending Term() message")))
+            .map_err(|_| failure::err_msg("Failed sending Term() message"))
     }
 
     /// Ping the peer.

          
@@ 566,7 559,7 @@ impl<'a> Client<'a> {
                 .into_iter()
                 .map(|s| dbus::Path::new(s).unwrap())
                 .collect()),
-            None => Err(ClientErrorKind::BadReturnType)?,
+            None => Err(ClientErrorKind::BadReturnType.into()),
         }
     }
 

          
@@ 588,7 581,7 @@ impl<'a> Client<'a> {
 
     pub fn set(&self, dev: dbus::Path, val: u32) -> Result<(), ClientError> {
         if val > 100 {
-            return Err(ClientErrorKind::BrightnessRange)?;
+            return Err(ClientErrorKind::BrightnessRange.into());
         }
         let obj = self.conn.with_path(self.peer.clone(), dev, self.timeout);
         obj.set(DEVICE_IFACE, "Brightness", val)

          
@@ 610,7 603,7 @@ impl<'a> Client<'a> {
     /// Decreases the brightness, clipping at minimum value provided.
     pub fn dec(&self, dev: dbus::Path, step: u32, min: u32) -> Result<u32, ClientError> {
         if min > 100 {
-            return Err(ClientErrorKind::BrightnessRange)?;
+            return Err(ClientErrorKind::BrightnessRange.into());
         }
         let cur = self.get(dev.clone())?;
         let new: u32 = match cur as i32 - step as i32 {

          
@@ 669,6 662,6 @@ impl From<ClientErrorKind> for ClientErr
 
 impl From<failure::Context<ClientErrorKind>> for ClientError {
     fn from(inner: failure::Context<ClientErrorKind>) -> ClientError {
-        ClientError { inner: inner }
+        ClientError { inner }
     }
 }

          
M src/lib.rs +4 -4
@@ 16,10 16,10 @@ pub fn create_devices(only: Vec<String>)
             Err(e) => return Err(From::from(e)),
         }
     }
-    if only.len() > 0 {
+    if !only.is_empty() {
         devices.retain(|d| only.contains(&String::from(d.name())));
     }
-    return Ok(devices);
+    Ok(devices)
 }
 
 // A backlight device, create via BacklightDeviceIter

          
@@ 77,7 77,7 @@ impl BacklightDevice {
         let path = self.path.join("brightness");
         let mut fp = fs::File::create(&path)?;
         write!(fp, "{}", n)?;
-        return Ok(n);
+        Ok(n)
     }
 
     // Get brightness as percentage

          
@@ 154,7 154,7 @@ mod tests {
         let mut maxfp = fs::File::create(maxfn).unwrap();
         write!(maxfp, "{}", max).unwrap();
 
-        return dir;
+        dir
     }
 
     #[test]

          
M src/pond.rs +9 -0
@@ 110,6 110,15 @@ impl<T: Send + 'static> Pond<T> {
     }
 }
 
+impl<T> Default for Pond<T>
+where
+    T: Send + 'static,
+{
+    fn default() -> Self {
+        Self::new()
+    }
+}
+
 pub struct TerminatedThread<T> {
     pub name: String,
     /// The Ok value contains the return value of the thread, possibly