pub(crate) struct SometimesUnboundedSink<T, S> {
buf: VecDeque<T>,
inner: S,
}Expand description
Wraps a [Sink], providing an only-sometimes-used unbounded buffer
For example, consider SometimesUnboundedSink<T, mpsc::Receiver>.
The Receiver is not always ready for writing:
if the capacity is exceeded, send will block.
SometimesUnboundedSink’s Sink implementation works the same way.
But there are also two methods
pollish_send_unbounded
and
send_unbounded
which will always succeed immediately.
Items which the underlying sink S is not ready to accept are queued,
and will be delivered to S when possible.
§You must poll this type
For queued items to be delivered,
SometimesUnboundedSink must be polled,
even if you don’t have an item to send.
You can use [Sink::poll_ready] for this.
Any Context-taking methods is suitable.
(This is a difference between SometimesUnboundedSink
and mpsc::UnboundedSender:
UnboundedSender::unbounded_send
does not require a flush operation.
In this way, SometimesUnboundedSink::send_unbounded behaves more like
[Sink::start_send], which does require a subsequent flush.)
§Error handling
Errors from the underlying sink may not be reported immediately,
due to the buffering in SometimesUnboundedSink.
However, if the sink reports errors from poll_ready
these will surface in a timely fashion.
After an error has been reported, there may still be buffered data,
which will only be delivered if SometimesUnboundedSink is polled again
(and the error in the underlying sink was transient).
Fields§
§buf: VecDeque<T>Things we couldn’t send_unbounded right away
Invariants:
-
Everything here must be fed to
innerbefore any further user data (unbounded user data may be appended). -
If this is nonempty, the executor knows to wake this task. This is achieved as follows: If this is nonempty,
inner.poll_ready()has been called.
inner: SThe actual sink
This also has the relevant Waker.
§Waker invariant
Whenever either
- The last call to any of our public methods returned
Pending, or bufis nonempty,
the last method call inner also returned Pending.
(Or, we have reported an error.)
So, in those situations, this task has been recorded for wakeup
by inner (specifically, its other end, if it’s a channel)
when inner becomes readable.
Therefore this task will be woken up, and, if the caller actually polls us again (as is usual and is required by our docs), we’ll drain any queued data.
Implementations§
Source§impl<T, S> SometimesUnboundedSink<T, S>
impl<T, S> SometimesUnboundedSink<T, S>
Source§impl<T, S: Sink<T>> SometimesUnboundedSink<T, S>
impl<T, S: Sink<T>> SometimesUnboundedSink<T, S>
Sourcepub(crate) fn iter_queue(&self) -> impl Iterator<Item = &T> + '_
Available on crate feature circ-padding only.
pub(crate) fn iter_queue(&self) -> impl Iterator<Item = &T> + '_
circ-padding only.Return an iterator over the items queued in this sink.
(Used by circuit padding to see whether we have a cell queued for a given hop.)
Sourcepub(crate) fn pollish_send_unbounded(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
item: T,
) -> Result<(), S::Error>
pub(crate) fn pollish_send_unbounded( self: Pin<&mut Self>, cx: &mut Context<'_>, item: T, ) -> Result<(), S::Error>
Hand item to the inner Sink if possible, or queue it otherwise
Like a poll_... method in that it takes a Context.
That’s needed to make sure we get polled again
when the underlying sink can accept items.
But unlike a poll_... method in that it doesn’t return Poll,
since completion is always immediate.
Sourcepub(crate) async fn send_unbounded(
self: Pin<&mut Self>,
item: T,
) -> Result<(), S::Error>
pub(crate) async fn send_unbounded( self: Pin<&mut Self>, item: T, ) -> Result<(), S::Error>
Hand item to the inner Sink if possible, or queue it otherwise (async fn)
You must .await this, but it will never block.
(Its future is always Ready.)
Sourcefn flush_buf(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), S::Error>>
fn flush_buf( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), S::Error>>
Flush the buffer. On a Ready(()) return, it’s empty.
This satisfies the Waker invariant as if it were a public method.
Sourcepub(crate) fn as_inner(&self) -> &S
pub(crate) fn as_inner(&self) -> &S
Obtain a reference to the inner Sink, S
This method should be used with a little care, since it bypasses the wrapper.
For example, if S has interior mutability, and this method is used to
modify it, the SometimesUnboundedSink may malfunction.
Sourcepub(crate) fn as_inner_mut(&mut self) -> &mut S
pub(crate) fn as_inner_mut(&mut self) -> &mut S
Obtain a mutable reference to the inner Sink, S
This method should be used with extra care, since it bypasses the wrapper.
Before you call this method,
make sure you understand the internal invariants for SometimesUnboundedSink,
and make sure that you are not violating them.
In particular, do not queue anything onto the resulting Sink directly.
Trait Implementations§
Source§impl<T, S: Sink<T>> Sink<T> for SometimesUnboundedSink<T, S>
impl<T, S: Sink<T>> Sink<T> for SometimesUnboundedSink<T, S>
Source§type Error = <S as Sink<T>>::Error
type Error = <S as Sink<T>>::Error
Source§fn poll_ready(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Result<(), S::Error>>
fn poll_ready( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<(), S::Error>>
Sink to receive a value. Read moreSource§fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), S::Error>
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), S::Error>
poll_ready which returned Poll::Ready(Ok(())). Read moreimpl<'pin, T, S> Unpin for SometimesUnboundedSink<T, S>where
PinnedFieldsOf<__SometimesUnboundedSink<'pin, T, S>>: Unpin,
Auto Trait Implementations§
impl<T, S> Freeze for SometimesUnboundedSink<T, S>where
S: Freeze,
impl<T, S> RefUnwindSafe for SometimesUnboundedSink<T, S>where
S: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, S> Send for SometimesUnboundedSink<T, S>
impl<T, S> Sync for SometimesUnboundedSink<T, S>
impl<T, S> UnwindSafe for SometimesUnboundedSink<T, S>where
S: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PossiblyOption<T> for T
impl<T> PossiblyOption<T> for T
§impl<T, Item> SinkExt<Item> for Twhere
T: Sink<Item> + ?Sized,
impl<T, Item> SinkExt<Item> for Twhere
T: Sink<Item> + ?Sized,
§fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
fn with<U, Fut, F, E>(self, f: F) -> With<Self, Item, U, Fut, F>
§fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
fn with_flat_map<U, St, F>(self, f: F) -> WithFlatMap<Self, Item, U, St, F>
§fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
fn sink_map_err<E, F>(self, f: F) -> SinkMapErr<Self, F>
§fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
fn sink_err_into<E>(self) -> SinkErrInto<Self, Item, E>
Into trait. Read more§fn buffer(self, capacity: usize) -> Buffer<Self, Item>where
Self: Sized,
fn buffer(self, capacity: usize) -> Buffer<Self, Item>where
Self: Sized,
alloc only.§fn flush(&mut self) -> Flush<'_, Self, Item>where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self, Item>where
Self: Unpin,
§fn send(&mut self, item: Item) -> Send<'_, Self, Item>where
Self: Unpin,
fn send(&mut self, item: Item) -> Send<'_, Self, Item>where
Self: Unpin,
§fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>where
Self: Unpin,
fn feed(&mut self, item: Item) -> Feed<'_, Self, Item>where
Self: Unpin,
§fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St>
fn send_all<'a, St>(&'a mut self, stream: &'a mut St) -> SendAll<'a, Self, St>
§fn left_sink<Si2>(self) -> Either<Self, Si2>where
Si2: Sink<Item, Error = Self::Error>,
Self: Sized,
fn left_sink<Si2>(self) -> Either<Self, Si2>where
Si2: Sink<Item, Error = Self::Error>,
Self: Sized,
§fn right_sink<Si1>(self) -> Either<Si1, Self>where
Si1: Sink<Item, Error = Self::Error>,
Self: Sized,
fn right_sink<Si1>(self) -> Either<Si1, Self>where
Si1: Sink<Item, Error = Self::Error>,
Self: Sized,
§fn poll_ready_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>where
Self: Unpin,
fn poll_ready_unpin(
&mut self,
cx: &mut Context<'_>,
) -> Poll<Result<(), Self::Error>>where
Self: Unpin,
Sink::poll_ready] on Unpin
sink types.§fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>where
Self: Unpin,
fn start_send_unpin(&mut self, item: Item) -> Result<(), Self::Error>where
Self: Unpin,
Sink::start_send] on Unpin
sink types.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.