Skip to content

Commit

Permalink
Remove unused trait impls
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Sep 19, 2024
1 parent f68a4a3 commit 44209ee
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 31 deletions.
10 changes: 5 additions & 5 deletions src/codec/rtu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]>,
}
Expand Down Expand Up @@ -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,
}
Expand Down
31 changes: 11 additions & 20 deletions src/codec/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,28 @@ 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,
}
}
}

#[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;
Expand Down Expand Up @@ -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());
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Request<'a>> for RequestPdu<'a> {
Expand Down
4 changes: 2 additions & 2 deletions src/frame/rtu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/frame/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/service/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 44209ee

Please sign in to comment.