diff --git a/CHANGELOG.md b/CHANGELOG.md index be526279..de14ad03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Cargo.toml b/Cargo.toml index 39843d12..24042b91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,20 +31,34 @@ 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" } @@ -52,7 +66,7 @@ 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" @@ -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" @@ -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" diff --git a/README.md b/README.md index efcfbb0a..4e0a0b6d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/client/mod.rs b/src/client/mod.rs index e6789a19..e487d313 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -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 { diff --git a/src/client/sync/mod.rs b/src/client/sync/mod.rs index 06190232..e9e9524f 100644 --- a/src/client/sync/mod.rs +++ b/src/client/sync/mod.rs @@ -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::{ diff --git a/src/lib.rs b/src/lib.rs index 586b01ad..8091f8d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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))] diff --git a/src/server/mod.rs b/src/server/mod.rs index 0747b35f..72888606 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -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")]