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 more1.83.0 · Source§fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
fn skip_until(&mut self, byte: u8) -> Result<usize, Error>
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
)