Created
January 17, 2019 04:09
-
-
Save rust-play/28145134a2e7709ac0c95f108eb8f48f to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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