tower/tower-reconnect/src/future.rs

32 lines
606 B
Rust
Raw Normal View History

2019-04-08 20:11:09 -07:00
use crate::Error;
use pin_project::pin_project;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
2019-03-08 08:46:12 -08:00
#[pin_project]
2019-03-08 08:46:12 -08:00
pub struct ResponseFuture<F> {
#[pin]
2019-03-08 08:46:12 -08:00
inner: F,
}
impl<F> ResponseFuture<F> {
pub(crate) fn new(inner: F) -> Self {
ResponseFuture { inner }
}
}
impl<F, T, E> Future for ResponseFuture<F>
2019-03-08 08:46:12 -08:00
where
F: Future<Output = Result<T, E>>,
E: Into<Error>,
2019-03-08 08:46:12 -08:00
{
type Output = Result<T, Error>;
2019-03-08 08:46:12 -08:00
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.project().inner.poll(cx).map_err(Into::into)
2019-03-08 08:46:12 -08:00
}
}