Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #![feature(async_await, futures_api)]
  2.  
  3. use std::{
  4. future::Future,
  5. pin::Pin,
  6. task::{Context, Poll},
  7. };
  8.  
  9. struct CustomFuture<F> {
  10. inner: F,
  11. }
  12.  
  13. impl<F: Unpin> CustomFuture<F> {
  14. fn inner_pinned<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut F> {
  15. unsafe { self.map_unchecked_mut(|custom_fut| &mut custom_fut.inner) }
  16. }
  17. }
  18.  
  19. impl<F, T, E> Future for CustomFuture<F>
  20. where
  21. F: Future<Output = Result<T, E>> + Unpin,
  22. {
  23. type Output = F::Output;
  24.  
  25. fn poll(self: Pin<&mut Self>, waker: &mut Context<'_>) -> Poll<Self::Output> {
  26. match self.inner_pinned().poll(waker) {
  27. v @ Poll::Ready(Ok(_)) => v,
  28. v @ Poll::Pending => v,
  29. e @ Poll::Ready(Err(_)) => e,
  30. }
  31. }
  32. }
  33.  
  34. fn main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement