[][src]Struct blocking::BlockOn

pub struct BlockOn<T>(_);

Blocking interface for async I/O.

Sometimes async I/O needs to be used in a blocking manner. If calling block_on() manually all the time becomes too tedious, use this type for more convenient blocking on async I/O operations.

This type implements traits Iterator, Read, or Write if the inner type implements Stream, AsyncRead, or AsyncWrite, respectively.

If writing data through the Write trait, make sure to flush before dropping the BlockOn handle or some buffered data might get lost.

Implementations

impl<T> BlockOn<T>[src]

pub fn new(io: T) -> BlockOn<T>[src]

Wraps an async I/O handle into a blocking interface.

Examples

use blocking::BlockOn;
use futures::stream;

let stream = stream::once(async { 7 });
let iter = BlockOn::new(Box::pin(stream));

pub fn get_ref(&self) -> &T[src]

Gets a reference to the async I/O handle.

Examples

use blocking::BlockOn;
use futures::prelude::*;

let stream = stream::once(async { 7 });
let iter = BlockOn::new(Box::pin(stream));

println!("{:?}", iter.get_ref().size_hint());

pub fn get_mut(&mut self) -> &mut T[src]

Gets a mutable reference to the async I/O handle.

Examples

use blocking::{block_on, BlockOn};
use futures::prelude::*;

let stream = stream::once(async { 7 });
let mut iter = BlockOn::new(Box::pin(stream));

let val = block_on(async {
    // This is async `next()` on the inner stream.
    iter.get_mut().next().await
});

assert_eq!(val, Some(7));
assert_eq!(iter.next(), None);

pub fn into_inner(self) -> T[src]

Extracts the inner async I/O handle.

Examples

use blocking::BlockOn;
use futures::stream;

let stream = stream::once(async { 7 });
let iter = BlockOn::new(Box::pin(stream));

// The inner pinned stream.
let stream = iter.into_inner();

Trait Implementations

impl<T: Debug> Debug for BlockOn<T>[src]

impl<T: Stream + Unpin> Iterator for BlockOn<T>[src]

type Item = T::Item

The type of the elements being iterated over.

impl<T: AsyncRead + Unpin> Read for BlockOn<T>[src]

impl<T: AsyncWrite + Unpin> Write for BlockOn<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for BlockOn<T> where
    T: RefUnwindSafe

impl<T> Send for BlockOn<T> where
    T: Send

impl<T> Sync for BlockOn<T> where
    T: Sync

impl<T> Unpin for BlockOn<T> where
    T: Unpin

impl<T> UnwindSafe for BlockOn<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.