Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 17, 2019 04:09
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/28145134a2e7709ac0c95f108eb8f48f to your computer and use it in GitHub Desktop.
Save rust-play/28145134a2e7709ac0c95f108eb8f48f to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
extern crate futures; // 0.1.25
use futures::prelude::*;
use futures::future::{ok, err};
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 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