[][src]Crate pasts

Minimal and simpler alternative to the futures crate.

Optional Features

The std feature is enabled by default, disable it to use on no_std.

Getting Started

This example pulls in a timer future from the async-std crate, then executes it with the pasts executor.

Add the following to your Cargo.toml:

pasts = "0.7"
aysnc-std = "1.0"
use core::{time::Duration, future::Future, task::{Context, Poll}, pin::Pin};
use async_std::task;
use pasts::{exec, wait};

/// An event handled by the event loop.
enum Event {

/// Shared state between tasks on the thread.
struct State(usize);

impl State {
    /// Event loop.  Return false to stop program.
    fn event(&mut self, event: Event) {
        match event {
            Event::One(()) => {
                println!("One {}", self.0);
                self.0 += 1;
                if self.0 > 5 {
            Event::Two(()) => {
                println!("Two {}", self.0);
                self.0 += 1

struct Interval(Duration, Pin<Box<dyn Future<Output = ()>>>);

impl Interval {
    fn new(duration: Duration) -> Self {
        Interval(duration, Box::pin(task::sleep(duration)))

impl Future for &mut Interval {
    type Output = ();

    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
        match self.1.as_mut().poll(cx) {
            Poll::Pending => Poll::Pending,
            Poll::Ready(()) => {
                self.1 = Box::pin(task::sleep(self.0));

fn main() {
    let mut state = State(0);
    let mut one = Interval::new(Duration::from_secs_f64(0.999));
    let mut two = Interval::new(Duration::from_secs_f64(2.0));

    exec!(state.event(wait! {
        Event::One((&mut one).await),
        Event::Two((&mut two).await),



Macro to remove boilerplate for executing an asynchronous event loop.


Create a future that waits on multiple futures concurrently and returns their results as a tuple.


Create a future that waits on multiple futures concurrently and returns the first result.


Similar to race!, except doesn't take an array, but rather a list of asynchronous expressions.



Execute a future on the current thread.