-
-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathfuture.rs
More file actions
42 lines (35 loc) · 996 Bytes
/
Copy pathfuture.rs
File metadata and controls
42 lines (35 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::{
fmt,
pin::Pin,
task::{self, Poll},
};
use http::Response;
use crate::core::{body::Incoming, client::Error};
/// A `Future` that will resolve to an HTTP Response.
#[must_use = "futures do nothing unless polled"]
pub struct ResponseFuture {
inner: Pin<Box<dyn Future<Output = Result<Response<Incoming>, Error>> + Send>>,
}
impl ResponseFuture {
#[inline]
pub(super) fn new<F>(value: F) -> ResponseFuture
where
F: Future<Output = Result<Response<Incoming>, Error>> + Send + 'static,
{
ResponseFuture {
inner: Box::pin(value),
}
}
}
impl fmt::Debug for ResponseFuture {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.pad("Future<Response>")
}
}
impl Future for ResponseFuture {
type Output = Result<Response<Incoming>, Error>;
#[inline]
fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<Self::Output> {
self.inner.as_mut().poll(cx)
}
}