diff --git a/Cargo.toml b/Cargo.toml index 3bc03abb..38bd09c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,25 +25,25 @@ all-features = true # [dependencies] -async-trait = "0.1.75" +async-trait = "0.1.77" byteorder = "1.5.0" bytes = "1.5.0" -futures = { version = "0.3.29", optional = true } -futures-util = { version = "0.3.29", optional = true, default-features = false } +futures-core = { version = "0.3.30", optional = true, default-features = false } +futures-util = { version = "0.3.30", optional = true, default-features = false } log = "0.4.20" -smallvec = { version = "1.11.2", default-features = false } +smallvec = { version = "1.11.2", optional = true, default-features = false } socket2 = { version = "0.5.5", optional = true, default-features = false } tokio = { version = "1.35.1", 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.10", default-features = false, features = [ +tokio-util = { version = "0.7.10", optional = true, default-features = false, features = [ "codec", ] } [dev-dependencies] -anyhow = "1.0.76" +anyhow = "1.0.79" env_logger = "0.10.1" -futures = "0.3.29" +futures = "0.3.30" tokio = { version = "1.35.1", default-features = false, features = [ "macros", "rt-multi-thread", @@ -58,8 +58,13 @@ webpki = "0.22.4" [features] default = ["rtu", "tcp"] -rtu = ["futures-util/sink"] -tcp = ["tokio/net", "futures-util/sink"] +rtu = [ + "dep:futures-core", + "futures-util/sink", + "dep:smallvec", + "dep:tokio-util", +] +tcp = ["dep:futures-core", "futures-util/sink", "tokio/net", "dep:tokio-util"] rtu-sync = ["rtu", "sync", "dep:tokio-serial"] tcp-sync = ["tcp", "sync"] rtu-server = ["rtu", "server", "tokio/macros", "dep:tokio-serial"] @@ -70,16 +75,10 @@ tcp-server = [ "tokio/macros", "tokio/rt-multi-thread", ] -rtu-over-tcp-server = [ - "rtu", - "server", - "socket2/all", - "tokio/macros", - "tokio/rt-multi-thread", -] +rtu-over-tcp-server = ["rtu", "tcp-server"] # The following features are internal and must not be used in dependencies. -sync = ["dep:futures", "tokio/time", "tokio/rt"] -server = ["dep:futures"] +sync = ["dep:futures-core", "futures-util/sink", "tokio/time", "tokio/rt"] +server = [] [badges] maintenance = { status = "actively-developed" } diff --git a/examples/rtu-over-tcp-server.rs b/examples/rtu-over-tcp-server.rs index 57f3aa02..5ab5fb96 100644 --- a/examples/rtu-over-tcp-server.rs +++ b/examples/rtu-over-tcp-server.rs @@ -8,12 +8,12 @@ use std::{ collections::HashMap, + future, net::SocketAddr, sync::{Arc, Mutex}, time::Duration, }; -use futures::future; use tokio::net::TcpListener; use tokio_modbus::{ diff --git a/examples/rtu-server-address.rs b/examples/rtu-server-address.rs index c83ee0ce..705b32bb 100644 --- a/examples/rtu-server-address.rs +++ b/examples/rtu-server-address.rs @@ -3,9 +3,7 @@ //! RTU server example with slave address filtering and optional response -use std::{thread, time::Duration}; - -use futures::future; +use std::{future, thread, time::Duration}; use tokio_modbus::{prelude::*, server::rtu::Server}; diff --git a/examples/rtu-server.rs b/examples/rtu-server.rs index 1fc1e0eb..0b943d62 100644 --- a/examples/rtu-server.rs +++ b/examples/rtu-server.rs @@ -3,9 +3,7 @@ //! RTU server example -use std::{thread, time::Duration}; - -use futures::future; +use std::{future, thread, time::Duration}; use tokio_modbus::{prelude::*, server::rtu::Server}; diff --git a/examples/tcp-server.rs b/examples/tcp-server.rs index ba9d8096..fc52a653 100644 --- a/examples/tcp-server.rs +++ b/examples/tcp-server.rs @@ -8,12 +8,12 @@ use std::{ collections::HashMap, + future, net::SocketAddr, sync::{Arc, Mutex}, time::Duration, }; -use futures::future; use tokio::net::TcpListener; use tokio_modbus::{ diff --git a/examples/tls-server.rs b/examples/tls-server.rs index f328497f..fc661a0b 100644 --- a/examples/tls-server.rs +++ b/examples/tls-server.rs @@ -9,6 +9,7 @@ use std::{ collections::HashMap, fs::File, + future, io::{self, BufReader}, net::SocketAddr, path::Path, @@ -16,7 +17,6 @@ use std::{ time::Duration, }; -use futures::future; use pkcs8::der::Decode; use rustls_pemfile::{certs, pkcs8_private_keys}; use tokio::net::{TcpListener, TcpStream}; diff --git a/src/client/sync/mod.rs b/src/client/sync/mod.rs index 756403d2..d2898a80 100644 --- a/src/client/sync/mod.rs +++ b/src/client/sync/mod.rs @@ -11,7 +11,7 @@ pub mod tcp; use std::{future::Future, io::Result, time::Duration}; -use futures::future::Either; +use futures_util::future::Either; use crate::{frame::*, slave::*}; diff --git a/src/frame/mod.rs b/src/frame/mod.rs index 9e7b4e85..285014bc 100644 --- a/src/frame/mod.rs +++ b/src/frame/mod.rs @@ -443,11 +443,19 @@ impl From> for ResponsePdu { } } -#[cfg(feature = "server")] +#[cfg(any( + feature = "rtu-over-tcp-server", + feature = "rtu-server", + feature = "tcp-server" +))] #[derive(Debug, Clone, PartialEq, Eq)] pub struct OptionalResponsePdu(pub(crate) Option); -#[cfg(feature = "server")] +#[cfg(any( + feature = "rtu-over-tcp-server", + feature = "rtu-server", + feature = "tcp-server" +))] impl From> for OptionalResponsePdu where T: Into, @@ -457,7 +465,7 @@ where } } -#[cfg(feature = "server")] +#[cfg(any(feature = "rtu-server", feature = "tcp-server"))] impl From for OptionalResponsePdu where T: Into, diff --git a/src/server/rtu.rs b/src/server/rtu.rs index 4a71b9cb..f2a50fec 100644 --- a/src/server/rtu.rs +++ b/src/server/rtu.rs @@ -3,10 +3,9 @@ //! Modbus RTU server skeleton -use std::{io, path::Path}; +use std::{future::Future, io, path::Path}; -use futures::{Future, FutureExt as _}; -use futures_util::{SinkExt as _, StreamExt as _}; +use futures_util::{FutureExt as _, SinkExt as _, StreamExt as _}; use tokio_serial::SerialStream; use tokio_util::codec::Framed; diff --git a/src/server/rtu_over_tcp.rs b/src/server/rtu_over_tcp.rs index 088c3a58..ee25a94e 100644 --- a/src/server/rtu_over_tcp.rs +++ b/src/server/rtu_over_tcp.rs @@ -3,11 +3,10 @@ //! Modbus RTU over TCP server skeleton -use std::{io, net::SocketAddr}; +use std::{future::Future, io, net::SocketAddr}; use async_trait::async_trait; -use futures::{self, Future}; -use futures_util::{future::FutureExt as _, sink::SinkExt as _, stream::StreamExt as _}; +use futures_util::{FutureExt as _, SinkExt as _, StreamExt as _}; use socket2::{Domain, Socket, Type}; use tokio::{ io::{AsyncRead, AsyncWrite}, diff --git a/src/server/tcp.rs b/src/server/tcp.rs index dcdab17b..36a621b8 100644 --- a/src/server/tcp.rs +++ b/src/server/tcp.rs @@ -3,11 +3,10 @@ //! Modbus TCP server skeleton -use std::{io, net::SocketAddr}; +use std::{future::Future, io, net::SocketAddr}; use async_trait::async_trait; -use futures::{self, Future}; -use futures_util::{future::FutureExt as _, sink::SinkExt as _, stream::StreamExt as _}; +use futures_util::{FutureExt as _, SinkExt as _, StreamExt as _}; use socket2::{Domain, Socket, Type}; use tokio::{ io::{AsyncRead, AsyncWrite}, @@ -211,9 +210,7 @@ mod tests { use crate::{prelude::*, server::Service}; - use std::sync::Arc; - - use futures::future; + use std::{future, sync::Arc}; #[tokio::test] async fn delegate_service_through_deref_for_server() { diff --git a/src/service/rtu.rs b/src/service/rtu.rs index aae8d1ad..9c12cdde 100644 --- a/src/service/rtu.rs +++ b/src/service/rtu.rs @@ -6,7 +6,7 @@ use std::{ io::{Error, ErrorKind}, }; -use futures_util::{sink::SinkExt as _, stream::StreamExt as _}; +use futures_util::{SinkExt as _, StreamExt as _}; use tokio::io::{AsyncRead, AsyncWrite}; use tokio_util::codec::Framed; diff --git a/src/service/tcp.rs b/src/service/tcp.rs index f332d8ec..cb992f41 100644 --- a/src/service/tcp.rs +++ b/src/service/tcp.rs @@ -7,7 +7,7 @@ use std::{ sync::atomic::{AtomicU16, Ordering}, }; -use futures_util::{sink::SinkExt as _, stream::StreamExt as _}; +use futures_util::{SinkExt as _, StreamExt as _}; use tokio::io::{AsyncRead, AsyncWrite}; use tokio_util::codec::Framed;