Skip to content

Commit

Permalink
Split feature "sync" into "rtu-sync" and "tcp-sync"
Browse files Browse the repository at this point in the history
This is required to avoid an unused tokio-serial dependency that is
only needed for "rtu-sync" but not for "rtu" (async).
  • Loading branch information
uklotzde committed Jan 30, 2023
1 parent 1717f2c commit 0c3493d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

# Changelog

## v0.7.0 (Unreleased)

- Features: Replace "sync" with "rtu-sync" and "tcp-sync" respectively

## v0.6.0 (2023-01-30)

- Added support for the `MaskWriteRegister` function code.
Expand Down
30 changes: 20 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,38 @@ socket2 = { version = "0.4.7", optional = true, default-features = false }
tokio = { version = "1.25.0", default-features = false }
# Disable default-features to exclude unused dependency on libudev
tokio-serial = { version = "5.4.4", optional = true, default-features = false }
tokio-util = { version = "0.7.4", features = ["codec"] }
tokio-util = { version = "0.7.4", default-features = false, features = [
"codec",
] }

[dev-dependencies]
env_logger = "0.10.0"
futures = "0.3.25"
tokio = { version = "1.25.0", features = ["net", "macros", "io-util", "rt", "time"] }

[features]
default = ["tcp", "rtu"]
rtu = ["tokio-serial", "futures-util/sink"]
default = ["rtu", "tcp"]
rtu = ["futures-util/sink"]
tcp = ["tokio/net", "futures-util/sink"]
sync = ["tokio/rt"]
server = ["futures", "socket2/all", "tokio/macros", "tokio/rt", "tokio/rt-multi-thread"]
tcp-server-unstable = ["tcp", "server"]
rtu-sync = ["rtu", "tokio-serial"]
tcp-sync = ["tcp"]
server = ["futures"]
rtu-server = ["rtu", "server", "tokio/macros", "tokio-serial"]
tcp-server-unstable = [
"tcp",
"server",
"socket2/all",
"tokio/macros",
"tokio/rt-multi-thread",
]

[badges]
maintenance = { status = "actively-developed" }

[[example]]
name = "rtu-client-sync"
path = "examples/rtu-client-sync.rs"
required-features = ["rtu", "sync"]
required-features = ["rtu-sync"]

[[example]]
name = "rtu-client"
Expand All @@ -62,7 +72,7 @@ required-features = ["rtu"]
[[example]]
name = "rtu-server"
path = "examples/rtu-server.rs"
required-features = ["rtu", "server"]
required-features = ["rtu-server"]

[[example]]
name = "tcp-client-custom-fn"
Expand All @@ -72,7 +82,7 @@ required-features = ["tcp"]
[[example]]
name = "tcp-client-sync"
path = "examples/tcp-client-sync.rs"
required-features = ["tcp", "sync"]
required-features = ["tcp-sync"]

[[example]]
name = "tcp-client"
Expand All @@ -82,4 +92,4 @@ required-features = ["tcp"]
[[example]]
name = "tcp-server"
path = "examples/tcp-server.rs"
required-features = ["tcp", "server", "tcp-server-unstable"]
required-features = ["tcp-server-unstable"]
6 changes: 3 additions & 3 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ use async_trait::async_trait;

use crate::{frame::*, slave::*};

#[cfg(feature = "sync")]
pub mod sync;

#[cfg(feature = "rtu")]
pub mod rtu;

#[cfg(feature = "tcp")]
pub mod tcp;

#[cfg(any(feature = "rtu-sync", feature = "tcp-sync"))]
pub mod sync;

/// Transport independent asynchronous client trait
#[async_trait]
pub trait Client: SlaveContext + Send + Debug {
Expand Down
7 changes: 2 additions & 5 deletions src/client/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@

//! Synchronous Modbus client
// TODO: Add missing documentation
#![allow(missing_docs)]

/// RTU client connections
#[cfg(feature = "rtu")]
#[cfg(feature = "rtu-sync")]
pub mod rtu;

/// TCP client connections
#[cfg(feature = "tcp")]
#[cfg(feature = "tcp-sync")]
pub mod tcp;

use super::{
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#![warn(rust_2021_compatibility)]
#![warn(missing_debug_implementations)]
#![warn(unreachable_pub)]
#![warn(clippy::cast_lossless)]
// TODO (v0.6): Decorate functions with #[must_use]
//#![warn(clippy::must_use_candidate)]
#![cfg_attr(not(test), warn(unsafe_code))]
#![warn(clippy::all)]
#![warn(clippy::cast_lossless)]
Expand Down
12 changes: 9 additions & 3 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ pub mod tcp {
#[cfg(feature = "server")]
pub use crate::server;

#[allow(missing_docs)]
#[cfg(any(feature = "rtu-sync", feature = "tcp-sync"))]
pub mod sync {
pub use crate::client::sync::*;
}

///////////////////////////////////////////////////////////////////
/// Structs
///////////////////////////////////////////////////////////////////
Expand All @@ -43,13 +49,13 @@ pub use crate::slave::{Slave, SlaveId};
///////////////////////////////////////////////////////////////////
pub use crate::client::{Client, Reader, Writer};

#[cfg(feature = "sync")]
#[cfg(any(feature = "rtu-sync", feature = "tcp-sync"))]
pub use crate::client::sync::Client as SyncClient;

#[cfg(feature = "sync")]
#[cfg(any(feature = "rtu-sync", feature = "tcp-sync"))]
pub use crate::client::sync::Reader as SyncReader;

#[cfg(feature = "sync")]
#[cfg(any(feature = "rtu-sync", feature = "tcp-sync"))]
pub use crate::client::sync::Writer as SyncWriter;

pub use crate::slave::SlaveContext;
2 changes: 1 addition & 1 deletion src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// TODO: Add missing documentation
#![allow(missing_docs)]

#[cfg(feature = "rtu")]
#[cfg(feature = "rtu-server")]
pub mod rtu;

#[cfg(feature = "tcp-server-unstable")]
Expand Down

0 comments on commit 0c3493d

Please sign in to comment.