finchers_core/endpoint/
apply.rs1use super::{Context, Endpoint};
2use error::Error;
3use input::{Input, RequestBody};
4use poll::Poll;
5use task::{self, Task};
6
7pub fn apply_request<E>(endpoint: &E, input: &Input, body: RequestBody) -> ApplyRequest<E::Task>
9where
10 E: Endpoint + ?Sized,
11{
12 let in_flight = endpoint.apply(&mut Context::new(input));
13 ApplyRequest {
14 in_flight,
15 body: Some(body),
16 }
17}
18
19#[derive(Debug)]
23pub struct ApplyRequest<T> {
24 in_flight: Option<T>,
25 body: Option<RequestBody>,
26}
27
28impl<T: Task> ApplyRequest<T> {
29 pub fn poll_ready(&mut self, input: &Input) -> Poll<Result<T::Output, Error>> {
31 match self.in_flight {
32 Some(ref mut f) => {
33 let mut cx = task::Context::new(input, &mut self.body);
34 f.poll_task(&mut cx)
35 }
36 None => Poll::Ready(Err(Error::skipped())),
37 }
38 }
39}