mock_http_connector/response/
future.rs

1use crate::hyper::Response;
2use crate::{error::BoxError, IntoResponse};
3use std::{future::Future, pin::Pin};
4
5pub type ResponseFuture =
6    Pin<Box<dyn Future<Output = Result<Response<String>, BoxError>> + Send + Sync + 'static>>;
7
8/// Trait for [`Future`]s that return a valid response for [`crate::Returning`]
9///
10/// See [`IntoResponse`] for supported return types.
11///
12/// ## Example
13///
14/// ```rust
15/// # use mock_http_connector::IntoResponseFuture;
16/// let fut = async { "hello" };
17/// let res_fut = fut.into_response_future();
18/// ```
19pub trait IntoResponseFuture {
20    /// Return a [`Future`] that resolves to `Result<Response<String>, BoxError>`
21    fn into_response_future(self) -> ResponseFuture;
22}
23
24impl<F> IntoResponseFuture for F
25where
26    F: Future + Send + Sync + 'static,
27    F::Output: IntoResponse,
28{
29    fn into_response_future(self) -> ResponseFuture {
30        Box::pin(async { self.await.into_response() })
31    }
32}