Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![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(),
- }
- }
- }
- impl Future for Boop {
- type Item = ();
- type Error = ();
- fn poll(&mut self) -> Poll<(), ()> {
- match self {
- A => self.a(),
- 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();
- }
Add Comment
Please, Sign In to add comment