pub struct JoinReadWrite<R: AsyncRead, W: AsyncWrite> { /* private fields */ }
Expand description
Async readable/writeable that dispatches reads to R
and writes to W
AsyncRead
is forwarded to R
.
AsyncWrite
is forwarded to W
.
JoinReadWrite::new()
is the converse of
AsyncReadExt::split()
.
But, if R
and W
came from splitting a single AsyncRead + AsyncWrite
,
you probably want the reunite
or unsplit
method, instead of JoinReadWrite
.
Does not implement any kind of flushing behaviour when switching between reading and writing.
§Example
use tor_async_utils::JoinReadWrite;
use futures::{AsyncReadExt as _, AsyncWriteExt as _};
let read = b"hello\n";
let mut read = &read[..];
let mut write = Vec::<u8>::new();
let mut joined = JoinReadWrite::new(read, write);
let mut got = String::new();
let _: usize = joined.read_to_string(&mut got).await.unwrap();
assert_eq!(got, "hello\n");
let () = joined.write_all(b"some data").await.unwrap();
let (r, w) = joined.into_parts();
assert_eq!(w, b"some data");
Implementations§
Source§impl<R: AsyncRead, W: AsyncWrite> JoinReadWrite<R, W>
impl<R: AsyncRead, W: AsyncWrite> JoinReadWrite<R, W>
Sourcepub fn new(r: R, w: W) -> Self
pub fn new(r: R, w: W) -> Self
Join an AsyncRead
and an AsyncWrite
into a single impl AsyncRead + AsyncWrite
Sourcepub fn into_parts(self) -> (R, W)
pub fn into_parts(self) -> (R, W)
Dismantle a JoinReadWrite
into its constituent AsyncRead
and AsyncWrite
Trait Implementations§
Source§impl<R: AsyncRead, W: AsyncWrite> AsyncRead for JoinReadWrite<R, W>
impl<R: AsyncRead, W: AsyncWrite> AsyncRead for JoinReadWrite<R, W>
Source§impl<R: AsyncRead, W: AsyncWrite> AsyncWrite for JoinReadWrite<R, W>
impl<R: AsyncRead, W: AsyncWrite> AsyncWrite for JoinReadWrite<R, W>
Source§fn poll_write(
self: Pin<&mut Self>,
c: &mut Context<'_>,
data: &[u8],
) -> Poll<Result<usize, Error>>
fn poll_write( self: Pin<&mut Self>, c: &mut Context<'_>, data: &[u8], ) -> Poll<Result<usize, Error>>
Attempt to write bytes from
buf
into the object. Read moreSource§fn poll_flush(
self: Pin<&mut Self>,
c: &mut Context<'_>,
) -> Poll<Result<(), Error>>
fn poll_flush( self: Pin<&mut Self>, c: &mut Context<'_>, ) -> Poll<Result<(), Error>>
Attempt to flush the object, ensuring that any buffered data reach
their destination. Read more
impl<'pin, R: AsyncRead, W: AsyncWrite> Unpin for JoinReadWrite<R, W>where
PinnedFieldsOf<__JoinReadWrite<'pin, R, W>>: Unpin,
Auto Trait Implementations§
impl<R, W> Freeze for JoinReadWrite<R, W>
impl<R, W> RefUnwindSafe for JoinReadWrite<R, W>where
R: RefUnwindSafe,
W: RefUnwindSafe,
impl<R, W> Send for JoinReadWrite<R, W>
impl<R, W> Sync for JoinReadWrite<R, W>
impl<R, W> UnwindSafe for JoinReadWrite<R, W>where
R: UnwindSafe,
W: UnwindSafe,
Blanket Implementations§
§impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
§fn chain<R>(self, next: R) -> Chain<Self, R>where
Self: Sized,
R: AsyncRead,
fn chain<R>(self, next: R) -> Chain<Self, R>where
Self: Sized,
R: AsyncRead,
Creates an adaptor which will chain this stream with another. Read more
§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
Tries to read some bytes directly into the given
buf
in asynchronous
manner, returning a future type. Read more§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self>where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>],
) -> ReadVectored<'a, Self>where
Self: Unpin,
Creates a future which will read from the
AsyncRead
into bufs
using vectored
IO operations. Read more§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
Creates a future which will read exactly enough bytes to fill
buf
,
returning an error if end of file (EOF) is hit sooner. Read more§fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEnd<'a, Self>where
Self: Unpin,
Creates a future which will read all the bytes from this
AsyncRead
. Read more§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self>where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String,
) -> ReadToString<'a, Self>where
Self: Unpin,
Creates a future which will read all the bytes from this
AsyncRead
. Read more§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
§fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self>where
Self: Unpin,
Creates a future which will entirely flush this
AsyncWrite
. Read more§fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
fn close(&mut self) -> Close<'_, Self>where
Self: Unpin,
Creates a future which will entirely close this
AsyncWrite
.§fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self>where
Self: Unpin,
Creates a future which will write bytes from
buf
into the object. Read more§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self>where
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>],
) -> WriteVectored<'a, Self>where
Self: Unpin,
Creates a future which will write bytes from
bufs
into the object using vectored
IO operations. Read moreSource§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
Mutably borrows from an owned value. Read more