Skip to content

Commit

Permalink
Split futures dependency into futures-core and futures-util (slowtec#240
Browse files Browse the repository at this point in the history
)

* Split futures dependency into futures-core and futures-util

* Fix rtu-over-tcp-server build
  • Loading branch information
uklotzde authored Jan 3, 2024
1 parent 7a92937 commit 6b0ce5d
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 45 deletions.
35 changes: 17 additions & 18 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ all-features = true
# <https://users.rust-lang.org/t/psa-please-specify-precise-dependency-versions-in-cargo-toml/71277>

[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",
Expand All @@ -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"]
Expand All @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion examples/rtu-over-tcp-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
4 changes: 1 addition & 3 deletions examples/rtu-server-address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
4 changes: 1 addition & 3 deletions examples/rtu-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
2 changes: 1 addition & 1 deletion examples/tcp-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down
2 changes: 1 addition & 1 deletion examples/tls-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
use std::{
collections::HashMap,
fs::File,
future,
io::{self, BufReader},
net::SocketAddr,
path::Path,
sync::{Arc, Mutex},
time::Duration,
};

use futures::future;
use pkcs8::der::Decode;
use rustls_pemfile::{certs, pkcs8_private_keys};
use tokio::net::{TcpListener, TcpStream};
Expand Down
2 changes: 1 addition & 1 deletion src/client/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*};

Expand Down
14 changes: 11 additions & 3 deletions src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,19 @@ impl From<Result<Response, ExceptionResponse>> 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<ResponsePdu>);

#[cfg(feature = "server")]
#[cfg(any(
feature = "rtu-over-tcp-server",
feature = "rtu-server",
feature = "tcp-server"
))]
impl<T> From<Option<T>> for OptionalResponsePdu
where
T: Into<ResponsePdu>,
Expand All @@ -457,7 +465,7 @@ where
}
}

#[cfg(feature = "server")]
#[cfg(any(feature = "rtu-server", feature = "tcp-server"))]
impl<T> From<T> for OptionalResponsePdu
where
T: Into<ResponsePdu>,
Expand Down
5 changes: 2 additions & 3 deletions src/server/rtu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 2 additions & 3 deletions src/server/rtu_over_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
9 changes: 3 additions & 6 deletions src/server/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/service/rtu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/service/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 6b0ce5d

Please sign in to comment.