From 5fc0e5b3a229a76fd93b19800258375e4ac842e8 Mon Sep 17 00:00:00 2001 From: Bo Jeanes Date: Fri, 9 Sep 2022 16:58:43 +1000 Subject: [PATCH] Address clippy errors --- modbus-mqtt/src/modbus/connection.rs | 9 ++++----- modbus-mqtt/src/modbus/register.rs | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/modbus-mqtt/src/modbus/connection.rs b/modbus-mqtt/src/modbus/connection.rs index 777e675..1521221 100644 --- a/modbus-mqtt/src/modbus/connection.rs +++ b/modbus-mqtt/src/modbus/connection.rs @@ -52,7 +52,7 @@ pub(crate) async fn run( let send = mqtt.publish("state", "disconnected").await; debug!(?config, ?send, "shutting down modbus connection"); } - Err(error) => handle_tx.send(Err(error.into())).unwrap(), + Err(error) => handle_tx.send(Err(error)).unwrap(), } }); @@ -243,8 +243,8 @@ impl Connection { // Os { code: 36, kind: Uncategorized, message: "Operation now in progress" }' // Os { code: 35, kind: WouldBlock, message: "Resource temporarily unavailable" } // - match &response { - Err(error) => match error.kind() { + if let Err(error) = &response { + match error.kind() { std::io::ErrorKind::UnexpectedEof => { // THIS happening feels like a bug either in how I am using tokio_modbus or in tokio_modbus. It seems // like the underlying buffers get all messed up and restarting doesn't always fix it unless I wait a @@ -252,8 +252,7 @@ impl Connection { error!(?error, "Connection error, may not be recoverable"); } _ => error!(?error), - }, - _ => {} + } } // This probably just means that the register task died or is no longer monitoring the response. diff --git a/modbus-mqtt/src/modbus/register.rs b/modbus-mqtt/src/modbus/register.rs index b50d005..1841165 100644 --- a/modbus-mqtt/src/modbus/register.rs +++ b/modbus-mqtt/src/modbus/register.rs @@ -87,13 +87,13 @@ pub(crate) async fn subscribe( fn to_register(payload: &Payload) -> crate::Result { let Payload { bytes, topic } = payload; let address = topic - .rsplit("/") + .rsplit('/') .next() .expect("subscribed topic guarantees we have a last segment") .parse()?; Ok(AddressedRegister { address, - register: serde_json::from_slice(&bytes)?, + register: serde_json::from_slice(bytes)?, }) } @@ -101,13 +101,13 @@ pub(crate) async fn subscribe( select! { Some(ref payload) = input_registers.recv() => { match to_register(payload) { - Ok(register) => if let Err(_) = tx.send((RegisterType::Input, register)).await { break; }, + Ok(register) => if (tx.send((RegisterType::Input, register)).await).is_err() { break; }, Err(error) => warn!(?error, def=?payload.bytes, "ignoring invalid input register definition"), } }, Some(ref payload) = holding_registers.recv() => { match to_register(payload) { - Ok(register) => if let Err(_) = tx.send((RegisterType::Holding, register)).await { break; }, + Ok(register) => if (tx.send((RegisterType::Holding, register)).await).is_err() { break; }, Err(error) => warn!(?error, def=?payload.bytes, "ignoring invalid holding register definition"), } }