diff --git a/src/codec/mod.rs b/src/codec/mod.rs index d6808b5..aaa17ff 100644 --- a/src/codec/mod.rs +++ b/src/codec/mod.rs @@ -138,7 +138,7 @@ impl<'r> TryFrom<&'r [u8]> for Request<'r> { return Err(Error::ByteCount(write_count)); } let data = Data { - quantity: write_quantity as usize, + quantity: write_quantity, data: &bytes[10..10 + write_count as usize], }; ReadWriteMultipleRegisters(read_address, read_quantity, write_address, data) diff --git a/src/codec/rtu/mod.rs b/src/codec/rtu/mod.rs index a2e0eac..fa18874 100644 --- a/src/codec/rtu/mod.rs +++ b/src/codec/rtu/mod.rs @@ -69,14 +69,13 @@ pub fn decode( Response => "response", }; if drop_cnt + 1 >= MAX_FRAME_LEN { - error!( - "Giving up to decode frame after dropping {} byte(s): {:X?}", - drop_cnt, + log::error!( + "Giving up to decode frame after dropping {drop_cnt} byte(s): {:X?}", &buf[0..drop_cnt] ); return Err(err); } - warn!("Failed to decode {} frame: {}", pdu_type, err); + log::warn!("Failed to decode {pdu_type} frame: {err}"); drop_cnt += 1; retry = true; Ok(None) diff --git a/src/codec/rtu/server.rs b/src/codec/rtu/server.rs index d3ff541..6a05909 100644 --- a/src/codec/rtu/server.rs +++ b/src/codec/rtu/server.rs @@ -15,7 +15,7 @@ pub fn decode_request(buf: &[u8]) -> Result> { .map(|pdu| Some(RequestAdu { hdr, pdu })) .map_err(|err| { // Unrecoverable error - error!("Failed to decode request PDU: {}", err); + log::error!("Failed to decode request PDU: {err}"); err }) } else { diff --git a/src/codec/tcp/mod.rs b/src/codec/tcp/mod.rs index 92fe7cb..fa2518b 100644 --- a/src/codec/tcp/mod.rs +++ b/src/codec/tcp/mod.rs @@ -70,14 +70,13 @@ pub fn decode( Response => "response", }; if drop_cnt + 1 >= MAX_FRAME_LEN { - error!( - "Giving up to decode frame after dropping {} byte(s): {:X?}", - drop_cnt, + log::error!( + "Giving up to decode frame after dropping {drop_cnt} byte(s): {:X?}", &buf[0..drop_cnt] ); return Err(err); } - warn!("Failed to decode {} frame: {}", pdu_type, err); + log::warn!("Failed to decode {pdu_type} frame: {err}"); drop_cnt += 1; retry = true; Ok(None) diff --git a/src/codec/tcp/server.rs b/src/codec/tcp/server.rs index 1624713..fad9190 100644 --- a/src/codec/tcp/server.rs +++ b/src/codec/tcp/server.rs @@ -25,7 +25,7 @@ pub fn decode_request(buf: &[u8]) -> Result> { .map(|pdu| Some(RequestAdu { hdr, pdu })) .map_err(|err| { // Unrecoverable error - error!("Failed to decode request PDU: {}", err); + log::error!("Failed to decode request PDU: {err}"); err }) } else { @@ -62,7 +62,7 @@ pub fn decode_response(buf: &[u8]) -> Result> { .map(|pdu| Some(ResponseAdu { hdr, pdu })) .map_err(|err| { // Unrecoverable error - error!("Failed to decode response PDU: {}", err); + log::error!("Failed to decode response PDU: {err}"); err }) } else { diff --git a/src/frame/coils.rs b/src/frame/coils.rs index 0eb289f..b693f77 100644 --- a/src/frame/coils.rs +++ b/src/frame/coils.rs @@ -109,7 +109,7 @@ pub fn pack_coils(coils: &[Coil], bytes: &mut [u8]) -> Result { } coils.iter().enumerate().for_each(|(i, b)| { let v = if *b { 0b1 } else { 0b0 }; - bytes[(i / 8) as usize] |= v << (i % 8); + bytes[i / 8] |= v << (i % 8); }); Ok(packed_size) } @@ -238,8 +238,8 @@ mod tests { #[test] fn convert_coil_to_bool() { - assert_eq!(u16_coil_to_bool(0xFF00).unwrap(), true); - assert_eq!(u16_coil_to_bool(0x0000).unwrap(), false); + assert!(u16_coil_to_bool(0xFF00).unwrap()); + assert!(!u16_coil_to_bool(0x0000).unwrap()); assert_eq!( u16_coil_to_bool(0x1234).err().unwrap(), Error::CoilValue(0x1234) diff --git a/src/lib.rs b/src/lib.rs index 85b46a6..9a91f8d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,9 +4,6 @@ #![doc = include_str!("../README.md")] #![no_std] -#[macro_use] -extern crate log; - mod codec; mod error; mod frame;