1//! Utilities used for the tor protocol.
23pub(crate) mod ct;
4pub(crate) mod err;
5pub(crate) mod keyed_futures_unordered;
6pub(crate) mod oneshot_broadcast;
7pub(crate) mod skew;
8pub(crate) mod sometimes_unbounded_sink;
9pub(crate) mod stream_poll_set;
10pub(crate) mod ts;
1112use futures::Sink;
13use std::pin::Pin;
14use std::task::{Context, Poll};
1516/// Extension trait for `Sink`
17pub(crate) trait SinkExt<T>: Sink<T> {
18/// Calls `futures::Sink::poll_ready` but requires `Unpin` and returns `bool`
19 ///
20 /// Various gnarly places in the circuit reactor find this convenient.
21 ///
22 /// TODO #1397 (circuit reactor) probably remove this when the circuit reactor is rewritten.
23fn poll_ready_unpin_bool(&mut self, cx: &mut Context<'_>) -> Result<bool, Self::Error>
24where
25Self: Unpin,
26 {
27Ok(match Sink::poll_ready(Pin::new(self), cx) {
28 Poll::Ready(Ok(())) => true,
29 Poll::Ready(Err(e)) => return Err(e),
30 Poll::Pending => false,
31 })
32 }
33}
34impl<T, S: Sink<T>> SinkExt<T> for S {}
3536/// Convenience alias for
37/// [`memquota::SpecificAccount::new_noop()`](crate::memquota::SpecificAccount::new_noop())
38///
39/// Available only in tests, which makes diff hunks which call this more obviously correct.
40#[cfg(any(test, feature = "testing"))]
41pub(crate) fn fake_mq<A: crate::memquota::SpecificAccount>() -> A {
42 A::new_noop()
43}