Struct tokio_util::io::SyncIoBridge
source · pub struct SyncIoBridge<T> { /* private fields */ }
io-util
and io
only.Expand description
Use a tokio::io::AsyncRead
synchronously as a std::io::Read
or
a tokio::io::AsyncWrite
as a std::io::Write
.
Implementations§
source§impl<T: AsyncWrite> SyncIoBridge<T>
impl<T: AsyncWrite> SyncIoBridge<T>
sourcepub fn is_write_vectored(&self) -> bool
pub fn is_write_vectored(&self) -> bool
Determines if the underlying tokio::io::AsyncWrite
target supports efficient vectored writes.
source§impl<T: AsyncWrite + Unpin> SyncIoBridge<T>
impl<T: AsyncWrite + Unpin> SyncIoBridge<T>
sourcepub fn shutdown(&mut self) -> Result<()>
pub fn shutdown(&mut self) -> Result<()>
Shutdown this writer. This method provides a way to call the AsyncWriteExt::shutdown
function of the inner tokio::io::AsyncWrite
instance.
§Errors
This method returns the same errors as AsyncWriteExt::shutdown
.
source§impl<T: Unpin> SyncIoBridge<T>
impl<T: Unpin> SyncIoBridge<T>
sourcepub fn new(src: T) -> Self
pub fn new(src: T) -> Self
Use a tokio::io::AsyncRead
synchronously as a std::io::Read
or
a tokio::io::AsyncWrite
as a std::io::Write
.
When this struct is created, it captures a handle to the current thread’s runtime with tokio::runtime::Handle::current
.
It is hence OK to move this struct into a separate thread outside the runtime, as created
by e.g. tokio::task::spawn_blocking
.
Stated even more strongly: to make use of this bridge, you must move
it into a separate thread outside the runtime. The synchronous I/O will use the
underlying handle to block on the backing asynchronous source, via
tokio::runtime::Handle::block_on
. As noted in the documentation for that
function, an attempt to block_on
from an asynchronous execution context
will panic.
§Wrapping !Unpin
types
Use e.g. SyncIoBridge::new(Box::pin(src))
.
§Panics
This will panic if called outside the context of a Tokio runtime.
sourcepub fn new_with_handle(src: T, rt: Handle) -> Self
pub fn new_with_handle(src: T, rt: Handle) -> Self
Use a tokio::io::AsyncRead
synchronously as a std::io::Read
or
a tokio::io::AsyncWrite
as a std::io::Write
.
This is the same as SyncIoBridge::new
, but allows passing an arbitrary handle and hence may
be initially invoked outside of an asynchronous context.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume this bridge, returning the underlying stream.
Trait Implementations§
source§impl<T: AsyncBufRead + Unpin> BufRead for SyncIoBridge<T>
impl<T: AsyncBufRead + Unpin> BufRead for SyncIoBridge<T>
source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
source§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
amt
bytes have been consumed from the buffer,
so they should no longer be returned in calls to read
. Read moresource§fn read_line(&mut self, buf: &mut String) -> Result<usize>
fn read_line(&mut self, buf: &mut String) -> Result<usize>
0xA
byte) is reached, and append
them to the provided String
buffer. Read moresource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
buf_read_has_data_left
)Read
has any data left to be read. Read moresource§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
bufread_skip_until
)byte
or EOF is reached. Read moresource§impl<T: Debug> Debug for SyncIoBridge<T>
impl<T: Debug> Debug for SyncIoBridge<T>
source§impl<T: AsyncRead + Unpin> Read for SyncIoBridge<T>
impl<T: AsyncRead + Unpin> Read for SyncIoBridge<T>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize>
buf
. Read moresource§fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize>
buf
. Read moresource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
buf
. Read more1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)source§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read moresource§impl<T: AsyncSeek + Unpin> Seek for SyncIoBridge<T>
impl<T: AsyncSeek + Unpin> Seek for SyncIoBridge<T>
source§fn seek(&mut self, pos: SeekFrom) -> Result<u64>
fn seek(&mut self, pos: SeekFrom) -> Result<u64>
1.55.0 · source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len
)source§impl<T: AsyncWrite + Unpin> Write for SyncIoBridge<T>
impl<T: AsyncWrite + Unpin> Write for SyncIoBridge<T>
source§fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write(&mut self, buf: &[u8]) -> Result<usize>
source§fn flush(&mut self) -> Result<()>
fn flush(&mut self) -> Result<()>
source§fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)