Guest User

Untitled

a guest
Jan 17th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #![feature(futures_api)]
  2.  
  3. extern crate futures; // 0.1.25
  4. use futures::prelude::*;
  5. use futures::future::{ok};
  6.  
  7. pub struct Boop {}
  8.  
  9. pub enum Cmd {
  10. A,
  11. B
  12. }
  13.  
  14. impl Boop {
  15. pub fn a(&mut self, ) -> impl Future<Item=(), Error=()> {
  16. ok(())
  17. }
  18.  
  19. pub fn b(&mut self, ) -> impl Future<Item=(), Error=()> {
  20. ok(())
  21. }
  22.  
  23. pub async fn c(&mut self, ) -> Result<(), ()> {
  24. Ok(())
  25. }
  26.  
  27. pub fn exec(&mut self, cmd: Cmd) -> impl Future<Item=(), Error=()> {
  28. match cmd {
  29. Cmd::A => self.a(),
  30. Cmd::B => self.b(),
  31. }
  32. }
  33. }
  34.  
  35. impl Future for Boop {
  36. type Item = ();
  37. type Error = ();
  38.  
  39. fn poll(&mut self) -> Poll<(), ()> {
  40. match self {
  41. A => self.a(),
  42. B => self.b()
  43. }
  44. }
  45. }
  46.  
  47. fn main() {
  48. let mut b = Boop{};
  49.  
  50. b.a().wait().unwrap();
  51. b.b().wait().unwrap();
  52. b.exec(Cmd::A).wait().unwrap();
  53. b.exec(Cmd::B).wait().unwrap();
  54. }
Add Comment
Please, Sign In to add comment