Struct cassette::Cassette[][src]

pub struct Cassette<T> where
    T: Future + Unpin
{ /* fields omitted */ }

A single-future non-blocking executor

Implementations

impl<T> Cassette<T> where
    T: Future + Unpin
[src]

pub fn new(thing: T) -> Self[src]

Create a new Cassette containing a single pinned future

Example

use cassette::{pin_mut, Cassette};

struct Demo {
    lol: u32,
}

impl Demo {
    async fn entry(&mut self) {
        /* Huzzah! */
    }
}

fn main() {
    // Make a new struct
    let mut demo = Demo { lol: 100 };

    // Call the entry point future, and pin it
    let x = demo.entry();
    pin_mut!(x);

    // Give the pinned future to Cassette
    // for execution
    let mut cm = Cassette::new(x);

    /* ... */
}

pub fn poll_on(&mut self) -> Option<<T as Future>::Output>[src]

Perform a “single step” of the future contained by this Cassette.

This is intended to be “polled to completion”, which might be for forever.

Example

use cassette::{pin_mut, Cassette};

struct Demo {
    lol: u32,
}

impl Demo {
    async fn entry(&mut self) {
        /* Huzzah! */
    }
}

fn main() {
    // Make a new struct
    let mut demo = Demo { lol: 100 };

    // Call the entry point future, and pin it
    let x = demo.entry();
    pin_mut!(x);

    // Give the pinned future to Cassette
    // for execution
    let mut cm = Cassette::new(x);

    while cm.poll_on().is_none() { }
    println!("Future done!");
}

pub fn block_on(self) -> <T as Future>::Output[src]

Block on the contained future forever

Panics

This method will panic if the contained future has already been completed as Poll::Ready(_).

pub fn is_done(&self) -> bool[src]

Has the contained future resolved to Poll::Ready(_) yet?

Auto Trait Implementations

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

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

impl<T> Unpin for Cassette<T>

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<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.