Guest User

Untitled

a guest
May 19th, 2019
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. use futures::future::BoxFuture;
  2.  
  3. pub trait Handler: Send {
  4. fn dispatch(&mut self, req: bson::Document) -> BoxFuture<'static, Result<bson::Document, KRPCError>>;
  5. }
  6.  
  7. // Convenience implementation to use Arc<Mutex<H>> as handlers.
  8. impl<H> Handler for Arc<Mutex<H>>
  9. where
  10. H: Handler + Send,
  11. {
  12. fn dispatch(&mut self, req: bson::Document) -> BoxFuture<'static, Result<bson::Document, KRPCError>> {
  13. async move {
  14. let lock = await!(self.lock());
  15. await!(lock.dispatch(req))
  16. }
  17. .boxed()
  18. }
  19. }
RAW Paste Data