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 29, 2022
1 parent 11e952c commit 6e5b11a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v0.6.0 (Unreleased)

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

## v0.5.2 (2021-12-05)

- Fix (RTU): Wrong byte count offset when writing multiple coils/registers
Expand Down
23 changes: 13 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,31 @@ socket2 = { version = "0.4", optional = true, default-features = false }
tokio = { version = "1", default-features = false }
# Disable default-features to exclude unused dependency on libudev
tokio-serial = { version = "5.4", optional = true, default-features = false }
tokio-util = { version = "0.6", features = ["codec"] }
tokio-util = { version = "0.6", default-features = false, features = ["codec"] }

[dev-dependencies]
env_logger = "0.9"
futures = "0.3"
tokio = { version = "1", features = ["net", "macros", "io-util", "rt", "time"] }
tokio-serial = { version = "5.4", default-features = false }

[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/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-serial"]
tcp-server-unstable = ["tcp", "server", "tokio/rt-multi-thread", "socket2/all"]

[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 @@ -56,7 +59,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 @@ -66,7 +69,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 @@ -76,4 +79,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
@@ -1,12 +1,12 @@
#[cfg(feature = "rtu")]
pub mod rtu;

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

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

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

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

use std::{
Expand Down
4 changes: 2 additions & 2 deletions src/client/sync/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Synchronous Modbus context access
#[cfg(feature = "rtu")]
#[cfg(feature = "rtu-sync")]
pub mod rtu;

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

use super::{
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
//! ## Sync TCP client
//!
//! ```rust,no_run
//! # #[cfg(all(feature = "tcp", feature = "sync"))]
//! # //FIXME: Run doc tests with `--features sync` to fix failure
//! # #[cfg(feature = "tcp-sync")]
//! # //FIXME: Run doc tests with `--features rtu-sync,tcp-sync` to fix failure
//! pub fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use tokio_modbus::prelude::*;
//!
Expand Down Expand Up @@ -114,8 +114,8 @@
//! ## Sync RTU client
//!
//! ```rust,no_run
//! # #[cfg(all(feature = "rtu", feature = "sync"))]
//! # //FIXME: Run doc tests with `--features sync` to fix failure
//! # #[cfg(feature = "rtu-sync")]
//! # //FIXME: Run doc tests with `--features rtu-sync,tcp-sync` to fix failure
//! pub fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use tokio_modbus::prelude::*;
//!
Expand Down
8 changes: 4 additions & 4 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub mod tcp {
pub use crate::server::*;
}

#[cfg(feature = "sync")]
#[cfg(any(feature = "rtu-sync", feature = "tcp-sync"))]
pub mod sync {
pub use crate::client::sync::*;
}
Expand All @@ -35,13 +35,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;
3 changes: 2 additions & 1 deletion src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#[cfg(feature = "rtu")]
#[cfg(feature = "rtu-server")]
pub mod rtu;

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

Expand Down

0 comments on commit 6e5b11a

Please sign in to comment.