Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 17, 2019 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/2a43fe1bf3c76e8fd033b8401cd8aac6 to your computer and use it in GitHub Desktop.
Save rust-play/2a43fe1bf3c76e8fd033b8401cd8aac6 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![feature(futures_api)]
extern crate futures; // 0.1.25
use futures::prelude::*;
use futures::future::{ok};
pub struct Boop {}
pub enum Cmd {
A,
B
}
impl Boop {
pub fn a(&mut self, ) -> impl Future<Item=(), Error=()> {
ok(())
}
pub fn b(&mut self, ) -> impl Future<Item=(), Error=()> {
ok(())
}
pub async fn c(&mut self, ) -> Result<(), ()> {
Ok(())
}
pub fn exec(&mut self, cmd: Cmd) -> impl Future<Item=(), Error=()> {
match cmd {
Cmd::A => self.a(),
Cmd::B => self.b(),
}
}
}
fn main() {
let mut b = Boop{};
b.a().wait().unwrap();
b.b().wait().unwrap();
b.exec(Cmd::A).wait().unwrap();
b.exec(Cmd::B).wait().unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment