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