From 25521a891b21051afbd208aa0252d6ff047e6839 Mon Sep 17 00:00:00 2001 From: Uwe Klotz Date: Tue, 10 Sep 2024 13:37:15 +0200 Subject: [PATCH] Exclude unused server code (#277) * Exclude unused server code * Run clippy with default feature (only client, no server) --- .pre-commit-config.yaml | 4 ++++ src/codec/rtu.rs | 12 ++++++++++++ src/codec/tcp.rs | 4 ++++ 3 files changed, 20 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 428991ad..2636f39e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -65,6 +65,10 @@ repos: hooks: - id: fmt args: [--all, --] + - id: clippy + # With default features + name: clippy + args: [--locked, --workspace, --all-targets, --, -D, warnings] - id: clippy name: clippy --all-features args: diff --git a/src/codec/rtu.rs b/src/codec/rtu.rs index 4628b005..7585aa26 100644 --- a/src/codec/rtu.rs +++ b/src/codec/rtu.rs @@ -103,6 +103,7 @@ impl FrameDecoder { } } +#[cfg(feature = "server")] #[derive(Debug, Default, Eq, PartialEq)] pub(crate) struct RequestDecoder { frame_decoder: FrameDecoder, @@ -118,11 +119,13 @@ pub(crate) struct ClientCodec { pub(crate) decoder: ResponseDecoder, } +#[cfg(feature = "server")] #[derive(Debug, Default, Eq, PartialEq)] pub(crate) struct ServerCodec { pub(crate) decoder: RequestDecoder, } +#[cfg(feature = "server")] fn get_request_pdu_len(adu_buf: &BytesMut) -> Result> { if let Some(fn_code) = adu_buf.get(1) { let len = match fn_code { @@ -213,6 +216,7 @@ fn check_crc(adu_data: &[u8], expected_crc: u16) -> Result<()> { Ok(()) } +#[cfg(feature = "server")] impl Decoder for RequestDecoder { type Item = (SlaveId, Bytes); type Error = Error; @@ -295,6 +299,7 @@ impl Decoder for ClientCodec { } } +#[cfg(feature = "server")] impl Decoder for ServerCodec { type Item = RequestAdu<'static>; type Error = Error; @@ -354,6 +359,7 @@ impl<'a> Encoder> for ClientCodec { } } +#[cfg(feature = "server")] impl Encoder for ServerCodec { type Error = Error; @@ -384,6 +390,7 @@ mod tests { } #[test] + #[cfg(feature = "server")] fn test_get_request_pdu_len() { let mut buf = BytesMut::new(); @@ -566,6 +573,7 @@ mod tests { } #[test] + #[cfg(feature = "server")] fn decode_empty_server_message() { let mut codec = ServerCodec::default(); let mut buf = BytesMut::new(); @@ -578,6 +586,7 @@ mod tests { } #[test] + #[cfg(feature = "server")] fn decode_single_byte_server_message() { let mut codec = ServerCodec::default(); let mut buf = BytesMut::from(&[0x00][..]); @@ -590,6 +599,7 @@ mod tests { } #[test] + #[cfg(feature = "server")] fn decode_partly_received_server_message_0x16() { let mut codec = ServerCodec::default(); let mut buf = BytesMut::from( @@ -607,6 +617,7 @@ mod tests { } #[test] + #[cfg(feature = "server")] fn decode_partly_received_server_message_0x0f() { let mut codec = ServerCodec::default(); let mut buf = BytesMut::from( @@ -624,6 +635,7 @@ mod tests { } #[test] + #[cfg(feature = "server")] fn decode_partly_received_server_message_0x10() { let mut codec = ServerCodec::default(); let mut buf = BytesMut::from( diff --git a/src/codec/tcp.rs b/src/codec/tcp.rs index 168dfb85..6defd8c4 100644 --- a/src/codec/tcp.rs +++ b/src/codec/tcp.rs @@ -33,11 +33,13 @@ impl Default for ClientCodec { } } +#[cfg(feature = "server")] #[derive(Debug, PartialEq)] pub(crate) struct ServerCodec { pub(crate) decoder: AduDecoder, } +#[cfg(feature = "server")] impl Default for ServerCodec { fn default() -> Self { Self { @@ -115,6 +117,7 @@ impl Decoder for ClientCodec { } } +#[cfg(feature = "server")] impl Decoder for ServerCodec { type Item = RequestAdu<'static>; type Error = Error; @@ -162,6 +165,7 @@ impl<'a> Encoder> for ClientCodec { } } +#[cfg(feature = "server")] impl Encoder for ServerCodec { type Error = Error;