[−][src]Struct smol::Unblock
Runs blocking I/O on a thread pool.
Blocking I/O must be isolated from async code. This type moves blocking I/O operations onto a special thread pool while exposing a familiar async interface.
This type implements traits Stream
, AsyncRead
, AsyncWrite
, or AsyncSeek
if the
inner type implements Iterator
, Read
, Write
, or Seek
, respectively.
If writing data through the AsyncWrite
trait, make sure to flush before dropping the
Unblock
handle or some buffered data might get lost.
Examples
use blocking::Unblock; use futures_lite::*; let mut stdout = Unblock::new(std::io::stdout()); stdout.write_all(b"Hello world!").await?; stdout.flush().await?;
Implementations
impl<T> Unblock<T>
[src]
pub fn new(io: T) -> Unblock<T>
[src]
Wraps a blocking I/O handle into the async Unblock
interface.
Examples
use blocking::Unblock; let stdin = Unblock::new(std::io::stdin());
pub async fn get_mut(&'_ mut self) -> &'_ mut T
[src]
Gets a mutable reference to the blocking I/O handle.
This is an async method because the I/O handle might be on the thread pool and needs to be moved onto the current thread before we can get a reference to it.
Examples
use blocking::Unblock; use std::fs::File; let mut file = Unblock::new(File::create("file.txt")?); let metadata = file.get_mut().await.metadata()?;
pub async fn with_mut<R, F>(&'_ mut self, op: F) -> R where
F: FnOnce(&mut T) -> R + Send + 'static,
R: Send + 'static,
T: Send + 'static,
[src]
F: FnOnce(&mut T) -> R + Send + 'static,
R: Send + 'static,
T: Send + 'static,
Performs a blocking operation on the I/O handle.
Examples
use blocking::Unblock; use std::fs::File; let mut file = Unblock::new(File::create("file.txt")?); let metadata = file.with_mut(|f| f.metadata()).await?;
pub async fn into_inner(self) -> T
[src]
Extracts the inner blocking I/O handle.
This is an async method because the I/O handle might be on the thread pool and needs to be moved onto the current thread before we can extract it.
Examples
use blocking::Unblock; use futures_lite::*; use std::fs::File; let mut file = Unblock::new(File::create("file.txt")?); file.write_all(b"Hello world!").await?; let file = file.into_inner().await;
Trait Implementations
impl<T> AsyncRead for Unblock<T> where
T: 'static + Read + Send,
[src]
T: 'static + Read + Send,
fn poll_read(
self: Pin<&mut Unblock<T>>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Unblock<T>>,
cx: &mut Context,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
fn poll_read_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &mut [IoSliceMut]
) -> Poll<Result<usize, Error>>
impl<T> AsyncSeek for Unblock<T> where
T: 'static + Seek + Send,
[src]
T: 'static + Seek + Send,
fn poll_seek(
self: Pin<&mut Unblock<T>>,
cx: &mut Context,
pos: SeekFrom
) -> Poll<Result<u64, Error>>
[src]
self: Pin<&mut Unblock<T>>,
cx: &mut Context,
pos: SeekFrom
) -> Poll<Result<u64, Error>>
impl<T> AsyncWrite for Unblock<T> where
T: 'static + Write + Send,
[src]
T: 'static + Write + Send,
fn poll_write(
self: Pin<&mut Unblock<T>>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Unblock<T>>,
cx: &mut Context,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_flush(
self: Pin<&mut Unblock<T>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Unblock<T>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
fn poll_close(
self: Pin<&mut Unblock<T>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Unblock<T>>,
cx: &mut Context
) -> Poll<Result<(), Error>>
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context,
bufs: &[IoSlice]
) -> Poll<Result<usize, Error>>
impl<T> Debug for Unblock<T> where
T: Debug,
[src]
T: Debug,
impl<T> Stream for Unblock<T> where
T: 'static + Send + Iterator,
<T as Iterator>::Item: Send,
<T as Iterator>::Item: 'static,
[src]
T: 'static + Send + Iterator,
<T as Iterator>::Item: Send,
<T as Iterator>::Item: 'static,
Auto Trait Implementations
impl<T> !RefUnwindSafe for Unblock<T>
impl<T> Send for Unblock<T> where
T: Send,
T: Send,
impl<T> !Sync for Unblock<T>
impl<T> Unpin for Unblock<T>
impl<T> !UnwindSafe for Unblock<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
[src]
R: AsyncRead + ?Sized,
fn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>ⓘImportant traits for ReadFuture<'_, T>
impl<'_, T> Future for ReadFuture<'_, T> where
T: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
Important traits for ReadFuture<'_, T>
impl<'_, T> Future for ReadFuture<'_, T> where
T: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>ⓘImportant traits for ReadVectoredFuture<'_, T>
impl<'_, T> Future for ReadVectoredFuture<'_, T> where
T: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>ⓘ
Important traits for ReadVectoredFuture<'_, T>
impl<'_, T> Future for ReadVectoredFuture<'_, T> where
T: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn read_to_end(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEndFuture<'a, Self>ⓘImportant traits for ReadToEndFuture<'_, T>
impl<'_, T> Future for ReadToEndFuture<'_, T> where
T: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
Important traits for ReadToEndFuture<'_, T>
impl<'_, T> Future for ReadToEndFuture<'_, T> where
T: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>ⓘImportant traits for ReadToStringFuture<'_, T>
impl<'_, T> Future for ReadToStringFuture<'_, T> where
T: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>ⓘ
Important traits for ReadToStringFuture<'_, T>
impl<'_, T> Future for ReadToStringFuture<'_, T> where
T: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>ⓘImportant traits for ReadExactFuture<'_, T>
impl<'_, T> Future for ReadExactFuture<'_, T> where
T: Unpin + AsyncRead + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
[src]
Important traits for ReadExactFuture<'_, T>
impl<'_, T> Future for ReadExactFuture<'_, T> where
T: Unpin + AsyncRead + ?Sized, type Output = Result<(), Error>;
Self: Unpin,
fn take(self, limit: u64) -> Take<Self>
[src]
fn bytes(self) -> Bytes<Self>
[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead,
[src]
R: AsyncRead,
impl<S> AsyncSeekExt for S where
S: AsyncSeek + ?Sized,
[src]
S: AsyncSeek + ?Sized,
fn seek(&mut self, pos: SeekFrom) -> SeekFuture<Self>ⓘImportant traits for SeekFuture<'_, T>
impl<'_, T> Future for SeekFuture<'_, T> where
T: Unpin + AsyncSeek + ?Sized, type Output = Result<u64, Error>;
where
Self: Unpin,
[src]
Important traits for SeekFuture<'_, T>
impl<'_, T> Future for SeekFuture<'_, T> where
T: Unpin + AsyncSeek + ?Sized, type Output = Result<u64, Error>;
Self: Unpin,
impl<R> AsyncWriteExt for R where
R: AsyncWrite + ?Sized,
[src]
R: AsyncWrite + ?Sized,
fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>ⓘImportant traits for WriteFuture<'_, T>
impl<'_, T> Future for WriteFuture<'_, T> where
T: Unpin + AsyncWrite + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
Important traits for WriteFuture<'_, T>
impl<'_, T> Future for WriteFuture<'_, T> where
T: Unpin + AsyncWrite + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>ⓘImportant traits for WriteVectoredFuture<'_, T>
impl<'_, T> Future for WriteVectoredFuture<'_, T> where
T: Unpin + AsyncWrite + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>ⓘ
Important traits for WriteVectoredFuture<'_, T>
impl<'_, T> Future for WriteVectoredFuture<'_, T> where
T: Unpin + AsyncWrite + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>ⓘImportant traits for WriteAllFuture<'_, T>
impl<'_, T> Future for WriteAllFuture<'_, T> where
T: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
[src]
Important traits for WriteAllFuture<'_, T>
impl<'_, T> Future for WriteAllFuture<'_, T> where
T: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
Self: Unpin,
fn flush(&mut self) -> FlushFuture<Self>ⓘImportant traits for FlushFuture<'_, T>
impl<'_, T> Future for FlushFuture<'_, T> where
T: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
[src]
Important traits for FlushFuture<'_, T>
impl<'_, T> Future for FlushFuture<'_, T> where
T: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
Self: Unpin,
fn close(&mut self) -> CloseFuture<Self>ⓘImportant traits for CloseFuture<'_, T>
impl<'_, T> Future for CloseFuture<'_, T> where
T: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
[src]
Important traits for CloseFuture<'_, T>
impl<'_, T> Future for CloseFuture<'_, T> where
T: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
Self: Unpin,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut Tⓘ
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> StreamExt for T where
T: Stream + ?Sized,
[src]
T: Stream + ?Sized,
fn next(&mut self) -> NextFuture<Self>ⓘImportant traits for NextFuture<'_, T>
impl<'_, T> Future for NextFuture<'_, T> where
T: Unpin + Stream + ?Sized, type Output = Option<<T as Stream>::Item>;
where
Self: Unpin,
[src]
Important traits for NextFuture<'_, T>
impl<'_, T> Future for NextFuture<'_, T> where
T: Unpin + Stream + ?Sized, type Output = Option<<T as Stream>::Item>;
Self: Unpin,
fn collect<C>(self) -> CollectFuture<Self, C>ⓘImportant traits for CollectFuture<St, C>
impl<St, C> Future for CollectFuture<St, C> where
C: Default + Extend<<St as Stream>::Item>,
St: Stream, type Output = C;
where
C: Default + Extend<Self::Item>,
[src]
Important traits for CollectFuture<St, C>
impl<St, C> Future for CollectFuture<St, C> where
C: Default + Extend<<St as Stream>::Item>,
St: Stream, type Output = C;
C: Default + Extend<Self::Item>,
fn try_collect<T, C>(self) -> TryCollectFuture<Self, C>ⓘImportant traits for TryCollectFuture<St, C>
impl<T, E, St, C> Future for TryCollectFuture<St, C> where
C: Default + Extend<T>,
St: Stream<Item = Result<T, E>>, type Output = Result<C, E>;
where
C: Default + Extend<T>,
Self::Item: Result,
<Self::Item as Result>::Ok == T,
[src]
Important traits for TryCollectFuture<St, C>
impl<T, E, St, C> Future for TryCollectFuture<St, C> where
C: Default + Extend<T>,
St: Stream<Item = Result<T, E>>, type Output = Result<C, E>;
C: Default + Extend<T>,
Self::Item: Result,
<Self::Item as Result>::Ok == T,
fn fold<B, F>(self, init: B, f: F) -> FoldFuture<Self, F, B>ⓘImportant traits for FoldFuture<S, F, B>
impl<S, F, B> Future for FoldFuture<S, F, B> where
F: FnMut(B, <S as Stream>::Item) -> B,
S: Stream, type Output = B;
where
F: FnMut(B, Self::Item) -> B,
[src]
Important traits for FoldFuture<S, F, B>
impl<S, F, B> Future for FoldFuture<S, F, B> where
F: FnMut(B, <S as Stream>::Item) -> B,
S: Stream, type Output = B;
F: FnMut(B, Self::Item) -> B,
fn try_fold<T, E, F, B>(&mut self, init: B, f: F) -> TryFoldFuture<Self, F, B>ⓘImportant traits for TryFoldFuture<'a, S, F, B>
impl<'a, T, E, S, F, B> Future for TryFoldFuture<'a, S, F, B> where
F: FnMut(B, T) -> Result<B, E>,
S: Stream + Unpin,
<S as Stream>::Item: Result,
<<S as Stream>::Item as Result>::Ok == T,
<<S as Stream>::Item as Result>::Err == E, type Output = Result<B, E>;
where
F: FnMut(B, T) -> Result<B, E>,
Self: Unpin,
Self::Item: Result,
<Self::Item as Result>::Ok == T,
<Self::Item as Result>::Err == E,
[src]
Important traits for TryFoldFuture<'a, S, F, B>
impl<'a, T, E, S, F, B> Future for TryFoldFuture<'a, S, F, B> where
F: FnMut(B, T) -> Result<B, E>,
S: Stream + Unpin,
<S as Stream>::Item: Result,
<<S as Stream>::Item as Result>::Ok == T,
<<S as Stream>::Item as Result>::Err == E, type Output = Result<B, E>;
F: FnMut(B, T) -> Result<B, E>,
Self: Unpin,
Self::Item: Result,
<Self::Item as Result>::Ok == T,
<Self::Item as Result>::Err == E,
fn boxed(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'static + Send>>ⓘ where
Self: Send + 'static,
[src]
Self: Send + 'static,
fn boxed_local(self) -> Pin<Box<dyn Stream<Item = Self::Item> + 'static>>ⓘ where
Self: 'static,
[src]
Self: 'static,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<S, T, E> TryStream for S where
S: Stream<Item = Result<T, E>> + ?Sized,
[src]
S: Stream<Item = Result<T, E>> + ?Sized,