Skip to content

Commit

Permalink
Exclude unused server code (slowtec#277)
Browse files Browse the repository at this point in the history
* Exclude unused server code

* Run clippy with default feature (only client, no server)
  • Loading branch information
uklotzde authored Sep 10, 2024
1 parent abb8539 commit 25521a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions src/codec/rtu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ impl FrameDecoder {
}
}

#[cfg(feature = "server")]
#[derive(Debug, Default, Eq, PartialEq)]
pub(crate) struct RequestDecoder {
frame_decoder: FrameDecoder,
Expand All @@ -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<Option<usize>> {
if let Some(fn_code) = adu_buf.get(1) {
let len = match fn_code {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -295,6 +299,7 @@ impl Decoder for ClientCodec {
}
}

#[cfg(feature = "server")]
impl Decoder for ServerCodec {
type Item = RequestAdu<'static>;
type Error = Error;
Expand Down Expand Up @@ -354,6 +359,7 @@ impl<'a> Encoder<RequestAdu<'a>> for ClientCodec {
}
}

#[cfg(feature = "server")]
impl Encoder<ResponseAdu> for ServerCodec {
type Error = Error;

Expand Down Expand Up @@ -384,6 +390,7 @@ mod tests {
}

#[test]
#[cfg(feature = "server")]
fn test_get_request_pdu_len() {
let mut buf = BytesMut::new();

Expand Down Expand Up @@ -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();
Expand All @@ -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][..]);
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions src/codec/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -115,6 +117,7 @@ impl Decoder for ClientCodec {
}
}

#[cfg(feature = "server")]
impl Decoder for ServerCodec {
type Item = RequestAdu<'static>;
type Error = Error;
Expand Down Expand Up @@ -162,6 +165,7 @@ impl<'a> Encoder<RequestAdu<'a>> for ClientCodec {
}
}

#[cfg(feature = "server")]
impl Encoder<ResponseAdu> for ServerCodec {
type Error = Error;

Expand Down

0 comments on commit 25521a8

Please sign in to comment.