Skip to content

Commit

Permalink
New features: "rtu-sync", "tcp-sync", "rtu-server"
Browse files Browse the repository at this point in the history
Split feature "sync" into "rtu-sync" and "tcp-sync". 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 Feb 13, 2023
1 parent cd1e0da commit a278969
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 24 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@

### Breaking Changes

- Features: Added "rtu-sync" as a replacement and superset of "rtu" and "sync"
- Features: Added "tcp-sync" as a replacement and superset of "tcp" and "sync"
- Features: Added "rtu-server" as a replacement and superset of "rtu" and "server"
- Server: Removed inconsistent `server::*` re-exports from `prelude::tcp`

## v0.6.1 (2023-02-13)
Expand Down
34 changes: 24 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,42 @@ 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.7", features = ["codec"] }
tokio-util = { version = "0.7.7", default-features = false, features = [
"codec",
] }

[dev-dependencies]
env_logger = "0.10.0"
futures = "0.3.26"
tokio = { version = "1.25.0", features = ["net", "macros", "io-util", "rt", "time"] }
tokio = { version = "1.25.0", default-features = false, features = ["macros", "rt-multi-thread", "time"] }
tokio-serial = { version = "5.4.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/macros", "tokio/rt", "tokio/rt-multi-thread"]
tcp-server-unstable = ["tcp", "server"]
# The internal feature "sync" has no effect when used alone.
# It is always enabled together with "rtu-sync" or "tcp-sync".
sync = []
rtu-sync = ["rtu", "sync", "dep:tokio-serial"]
tcp-sync = ["tcp", "sync"]
server = ["dep:futures"]
rtu-server = ["rtu", "server", "tokio/macros", "dep: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 +76,7 @@ required-features = ["rtu"]
[[example]]
name = "rtu-server"
path = "examples/rtu-server.rs"
required-features = ["rtu", "server"]
required-features = ["rtu-server"]

[[example]]
name = "rtu-server-address"
Expand All @@ -77,7 +91,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 Down
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,43 @@ Add this to your `Cargo.toml`:
tokio-modbus = "*"
```

If you like to use Modbus TCP only:
### Cargo Features

- `"rtu"`: Asynchronous RTU client (default)
- `"tcp"`: Asynchronous TCP client (default)
- `"rtu-sync`: Synchronous RTU client
- `"tcp-sync"`: Synchronous RTU client (default)
- `"rtu-server"`: (Asynchronous) RTU server
- `"tcp-server-unstable"`: (Asynchronous) TCP server (experimental)

#### Examples

If you only need an asynchronous TCP client add the following line to your Cargo.toml file:

```toml
[dependencies]
tokio-modbus = { version = "*", default-features = false, features = ["tcp"] }
```

If you like to use Modbus RTU only:
For an asynchronous RTU client:

```toml
[dependencies]
tokio-modbus = { version = "*", default-features = false, features = ["rtu"] }
```

If you like to build a TCP server:
For an RTU server:

```toml
[dependencies]
tokio-modbus = { version = "*", default-features = false, features = ["rtu-server"] }
```

For a TCP server:

```toml
[dependencies]
tokio-modbus = { version = "*", default-features = false, features = ["tcp", "server"] }
tokio-modbus = { version = "*", default-features = false, features = ["tcp-server-unstable"] }
```

## Examples
Expand Down
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(feature = "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
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
#![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)]
#![warn(clippy::explicit_deref_methods)]
#![warn(clippy::explicit_into_iter_loop)]
#![warn(clippy::explicit_iter_loop)]
// TODO (v0.6): Decorate functions with #[must_use]
// TODO: Decorate functions with #[must_use]
//#![warn(clippy::must_use_candidate)]
#![cfg_attr(not(test), warn(clippy::panic_in_result_fn))]
#![cfg_attr(not(test), warn(clippy::cast_possible_truncation))]
Expand Down
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 a278969

Please sign in to comment.