Struct SinkWriter
pub struct SinkWriter<S> { /* private fields */ }
Convert a Sink of byte chunks into an AsyncWrite.
Whenever you write to this SinkWriter, the supplied bytes are
forwarded to the inner Sink. When shutdown is called on this
SinkWriter, the inner sink is closed.
This adapter takes a Sink<&[u8]> and provides an AsyncWrite impl
for it. Because of the lifetime, this trait is relatively rarely
implemented. The main ways to get a Sink<&[u8]> that you can use with
this type are:
- With the codec module by implementing the
Encoder<&[u8]>trait. - By wrapping a
Sink<Bytes>in aCopyToBytes. - Manually implementing
Sink<&[u8]>directly.
The opposite conversion of implementing Sink<_> for an AsyncWrite
is done using the codec module.
Example
use Bytes;
use SinkExt;
use ;
use AsyncWriteExt;
use ;
use PollSender;
#
# async
Implementations
impl<S> SinkWriter<S>
fn new(sink: S) -> SelfCreates a new
SinkWriter.fn get_ref(&self) -> &SGets a reference to the underlying sink.
fn get_mut(&mut self) -> &mut SGets a mutable reference to the underlying sink.
fn into_inner(self) -> SConsumes this
SinkWriter, returning the underlying sink.
Trait Implementations
impl<'__pin, S> Unpin for SinkWriter<S>
where
PinnedFieldsOf<__Origin<'__pin, S>>: Unpin,
impl<S, E> AsyncWrite for SinkWriter<S>
where
for<'a> S: Sink<&'a [u8], Error = E>,
E: Into<Error>,
fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize, Error>>fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Error>>fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Error>>
impl<S: AsyncRead> AsyncRead for SinkWriter<S>
fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<Result<()>>
impl<S: Debug> Debug for SinkWriter<S>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl<S: Stream> Stream for SinkWriter<S>
type Item = <S as Stream>::Item;fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>
Auto Trait Implementations
impl<S> Freeze for SinkWriter<S>
where
S: Freeze,
impl<S> RefUnwindSafe for SinkWriter<S>
where
S: RefUnwindSafe,
impl<S> Send for SinkWriter<S>
where
S: Send,
impl<S> Sync for SinkWriter<S>
where
S: Sync,
impl<S> UnsafeUnpin for SinkWriter<S>
where
S: UnsafeUnpin,
impl<S> UnwindSafe for SinkWriter<S>
where
S: UnwindSafe,
Blanket Implementations
impl<R> AsyncReadExt for SinkWriter<S>
where
R: AsyncRead + ?Sized,
impl<S, T, E> TryStream for SinkWriter<S>
where
S: Stream<Item = Result<T, E>> + ?Sized,
type Ok = T;type Error = E;fn try_poll_next(self: Pin<&mut S>, cx: &mut Context<'_>) -> Poll<Option<Result<<S as TryStream>::Ok, <S as TryStream>::Error>>>
impl<T> Any for SinkWriter<S>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for SinkWriter<S>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for SinkWriter<S>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for SinkWriter<S>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for SinkWriter<S>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for SinkWriter<S>
where
U: Into<T>,
type Error = Infallible;fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for SinkWriter<S>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>