diff options
Diffstat (limited to 'crates/tor-proto')
| -rw-r--r-- | crates/tor-proto/Cargo.toml | 1 | ||||
| -rw-r--r-- | crates/tor-proto/src/stream/data.rs | 16 |
2 files changed, 11 insertions, 6 deletions
diff --git a/crates/tor-proto/Cargo.toml b/crates/tor-proto/Cargo.toml index 5e09870b5..d6385da5c 100644 --- a/crates/tor-proto/Cargo.toml +++ b/crates/tor-proto/Cargo.toml @@ -81,6 +81,7 @@ rand = "0.8" rand_core = "0.6.2" safelog = { path = "../safelog", version = "0.4.2" } slotmap-careful = { path = "../slotmap-careful", version = "0.2.1" } +static_assertions = "1" subtle = "2" thiserror = "2" tokio-crate = { package = "tokio", version = "1.7", optional = true } diff --git a/crates/tor-proto/src/stream/data.rs b/crates/tor-proto/src/stream/data.rs index 3cb301a0f..99746bcff 100644 --- a/crates/tor-proto/src/stream/data.rs +++ b/crates/tor-proto/src/stream/data.rs @@ -2,7 +2,7 @@ //! for byte-oriented communication. use crate::{Error, Result}; -use futures::future::BoxFuture; +use static_assertions::assert_impl_all; use tor_cell::relaycell::msg::EndReason; use tor_cell::relaycell::RelayCmd; @@ -127,6 +127,7 @@ pub struct DataStream { #[cfg(feature = "stream-ctrl")] ctrl: std::sync::Arc<ClientDataStreamCtrl>, } +assert_impl_all! { DataStream: Send, Sync } /// An object used to control and monitor a data stream. /// @@ -514,6 +515,9 @@ impl TokioAsyncWrite for DataStream { } } +/// Helper type: Like BoxFuture, but also requires that the future be Sync. +type BoxSyncFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + Sync + 'a>>; + /// An enumeration for the state of a DataWriter. /// /// We have to use an enum here because, for as long as we're waiting @@ -529,8 +533,8 @@ enum DataWriterState { Ready(DataWriterImpl), /// The writer is flushing a cell. Flushing( - #[educe(Debug(method = "skip_fmt"))] - Pin<Box<dyn Future<Output = (DataWriterImpl, Result<()>)> + Send>>, + #[educe(Debug(method = "skip_fmt"))] // + BoxSyncFuture<'static, (DataWriterImpl, Result<()>)>, ), } @@ -575,7 +579,7 @@ impl DataWriter { let state = self.state.take().expect("Missing state in DataWriter"); // TODO: this whole function is a bit copy-pasted. - let mut future: BoxFuture<_> = match state { + let mut future: BoxSyncFuture<_> = match state { DataWriterState::Ready(imp) => { if imp.n_pending == 0 { // Nothing to flush! @@ -771,8 +775,8 @@ enum DataReaderState { /// The reader is currently fetching a cell: this future is the /// progress it is making. ReadingCell( - #[educe(Debug(method = "skip_fmt"))] - Pin<Box<dyn Future<Output = (DataReaderImpl, Result<()>)> + Send>>, + #[educe(Debug(method = "skip_fmt"))] // + BoxSyncFuture<'static, (DataReaderImpl, Result<()>)>, ), } |
