Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(async_await, futures_api)]
- use std::{
- future::Future,
- pin::Pin,
- task::{Context, Poll},
- };
- struct CustomFuture<F> {
- inner: F,
- }
- impl<F: Unpin> CustomFuture<F> {
- fn inner_pinned<'a>(self: Pin<&'a mut Self>) -> Pin<&'a mut F> {
- unsafe { self.map_unchecked_mut(|custom_fut| &mut custom_fut.inner) }
- }
- }
- impl<F, T, E> Future for CustomFuture<F>
- where
- F: Future<Output = Result<T, E>> + Unpin,
- {
- type Output = F::Output;
- fn poll(self: Pin<&mut Self>, waker: &mut Context<'_>) -> Poll<Self::Output> {
- match self.inner_pinned().poll(waker) {
- v @ Poll::Ready(Ok(_)) => v,
- v @ Poll::Pending => v,
- e @ Poll::Ready(Err(_)) => e,
- }
- }
- }
- fn main() {}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement