diff --git a/src/codec/rtu.rs b/src/codec/rtu.rs index 95ff7616..8c0f551c 100644 --- a/src/codec/rtu.rs +++ b/src/codec/rtu.rs @@ -21,7 +21,7 @@ const MAX_FRAME_LEN: usize = 256; type DroppedBytes = SmallVec<[u8; MAX_FRAME_LEN]>; -#[derive(Debug, Eq, PartialEq)] +#[derive(Debug)] pub(crate) struct FrameDecoder { dropped_bytes: SmallVec<[u8; MAX_FRAME_LEN]>, } @@ -104,23 +104,23 @@ impl FrameDecoder { } #[cfg(feature = "server")] -#[derive(Debug, Default, Eq, PartialEq)] +#[derive(Debug, Default)] pub(crate) struct RequestDecoder { frame_decoder: FrameDecoder, } -#[derive(Debug, Default, Eq, PartialEq)] +#[derive(Debug, Default)] pub(crate) struct ResponseDecoder { frame_decoder: FrameDecoder, } -#[derive(Debug, Default, Eq, PartialEq)] +#[derive(Debug, Default)] pub(crate) struct ClientCodec { pub(crate) decoder: ResponseDecoder, } #[cfg(feature = "server")] -#[derive(Debug, Default, Eq, PartialEq)] +#[derive(Debug, Default)] pub(crate) struct ServerCodec { pub(crate) decoder: RequestDecoder, } diff --git a/src/codec/tcp.rs b/src/codec/tcp.rs index 0f86c978..7a3b1ce2 100644 --- a/src/codec/tcp.rs +++ b/src/codec/tcp.rs @@ -17,16 +17,16 @@ const HEADER_LEN: usize = 7; const PROTOCOL_ID: u16 = 0x0000; // TCP -#[derive(Debug, PartialEq)] +#[derive(Debug, Default)] pub(crate) struct AduDecoder; -#[derive(Debug, PartialEq)] +#[derive(Debug)] pub(crate) struct ClientCodec { pub(crate) decoder: AduDecoder, } -impl Default for ClientCodec { - fn default() -> Self { +impl ClientCodec { + pub(crate) const fn new() -> Self { Self { decoder: AduDecoder, } @@ -34,20 +34,11 @@ impl Default for ClientCodec { } #[cfg(feature = "server")] -#[derive(Debug, PartialEq)] +#[derive(Debug, Default)] pub(crate) struct ServerCodec { pub(crate) decoder: AduDecoder, } -#[cfg(feature = "server")] -impl Default for ServerCodec { - fn default() -> Self { - Self { - decoder: AduDecoder, - } - } -} - impl Decoder for AduDecoder { type Item = (Header, Bytes); type Error = Error; @@ -185,7 +176,7 @@ mod tests { #[test] fn decode_header_fragment() { - let mut codec = ClientCodec::default(); + let mut codec = ClientCodec::new(); let mut buf = BytesMut::from(&[0x00, 0x11, 0x00, 0x00, 0x00, 0x00][..]); let res = codec.decode(&mut buf).unwrap(); assert!(res.is_none()); @@ -194,7 +185,7 @@ mod tests { #[test] fn decode_partly_received_message() { - let mut codec = ClientCodec::default(); + let mut codec = ClientCodec::new(); let mut buf = BytesMut::from( &[ TRANSACTION_ID_HI, @@ -214,7 +205,7 @@ mod tests { #[test] fn decode_exception_message() { - let mut codec = ClientCodec::default(); + let mut codec = ClientCodec::new(); let mut buf = BytesMut::from( &[ TRANSACTION_ID_HI, @@ -243,7 +234,7 @@ mod tests { #[test] fn decode_with_invalid_protocol_id() { - let mut codec = ClientCodec::default(); + let mut codec = ClientCodec::new(); let mut buf = BytesMut::from( &[ TRANSACTION_ID_HI, @@ -263,7 +254,7 @@ mod tests { #[test] fn encode_read_request() { - let mut codec = ClientCodec::default(); + let mut codec = ClientCodec::new(); let mut buf = BytesMut::new(); let req = Request::ReadInputRegisters(0x23, 5); let pdu = req.clone().into(); @@ -289,7 +280,7 @@ mod tests { #[test] fn encode_with_limited_buf_capacity() { - let mut codec = ClientCodec::default(); + let mut codec = ClientCodec::new(); let pdu = Request::ReadInputRegisters(0x23, 5).into(); let hdr = Header { transaction_id: TRANSACTION_ID, diff --git a/src/frame/mod.rs b/src/frame/mod.rs index 8a8e113d..336c436f 100644 --- a/src/frame/mod.rs +++ b/src/frame/mod.rs @@ -502,7 +502,7 @@ pub struct ExceptionResponse { } /// Represents a message from the client (slave) to the server (master). -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] pub(crate) struct RequestPdu<'a>(pub(crate) Request<'a>); impl<'a> From> for RequestPdu<'a> { diff --git a/src/frame/rtu.rs b/src/frame/rtu.rs index 07b6989b..b483fd92 100644 --- a/src/frame/rtu.rs +++ b/src/frame/rtu.rs @@ -10,13 +10,13 @@ pub(crate) struct Header { pub(crate) slave_id: SlaveId, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] pub struct RequestAdu<'a> { pub(crate) hdr: Header, pub(crate) pdu: RequestPdu<'a>, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] pub(crate) struct ResponseAdu { pub(crate) hdr: Header, pub(crate) pdu: ResponsePdu, diff --git a/src/frame/tcp.rs b/src/frame/tcp.rs index 4c7b7f85..98b6c56e 100644 --- a/src/frame/tcp.rs +++ b/src/frame/tcp.rs @@ -12,13 +12,13 @@ pub(crate) struct Header { pub(crate) unit_id: UnitId, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] pub struct RequestAdu<'a> { pub(crate) hdr: Header, pub(crate) pdu: RequestPdu<'a>, } -#[derive(Debug, Clone, PartialEq, Eq)] +#[derive(Debug, Clone)] pub(crate) struct ResponseAdu { pub(crate) hdr: Header, pub(crate) pdu: ResponsePdu, diff --git a/src/service/tcp.rs b/src/service/tcp.rs index a4a478ac..97020288 100644 --- a/src/service/tcp.rs +++ b/src/service/tcp.rs @@ -33,7 +33,7 @@ where T: AsyncRead + AsyncWrite + Unpin, { pub(crate) fn new(transport: T, slave: Slave) -> Self { - let framed = Framed::new(transport, codec::tcp::ClientCodec::default()); + let framed = Framed::new(transport, codec::tcp::ClientCodec::new()); let unit_id: UnitId = slave.into(); let transaction_id = AtomicU16::new(INITIAL_TRANSACTION_ID); Self {