Skip to main content

wreq_proto/rt/
bounds.rs

1//! Trait aliases
2//!
3//! Traits in this module ease setting bounds and usually automatically
4//! implemented by implementing another trait.
5
6pub use self::h2_client::Http2ClientConnExec;
7
8mod h2_client {
9    use std::future::Future;
10
11    use tokio::io::{AsyncRead, AsyncWrite};
12
13    use crate::{error::BoxError, proto::http2::client::H2ClientFuture, rt::Executor};
14
15    /// An executor to spawn http2 futures for the client.
16    ///
17    /// This trait is implemented for any type that implements [`Executor`]
18    /// trait for any future.
19    ///
20    /// This trait is sealed and cannot be implemented for types outside this crate.
21    pub trait Http2ClientConnExec<B, T>: sealed_client::Sealed<(B, T)>
22    where
23        B: http_body::Body,
24        B::Error: Into<BoxError>,
25        T: AsyncRead + AsyncWrite + Unpin,
26    {
27        #[doc(hidden)]
28        fn execute_h2_future(&mut self, future: H2ClientFuture<B, T>);
29    }
30
31    impl<E, B, T> Http2ClientConnExec<B, T> for E
32    where
33        E: Executor<H2ClientFuture<B, T>>,
34        B: http_body::Body + 'static,
35        B::Error: Into<BoxError>,
36        H2ClientFuture<B, T>: Future<Output = ()>,
37        T: AsyncRead + AsyncWrite + Unpin,
38    {
39        #[inline]
40        fn execute_h2_future(&mut self, future: H2ClientFuture<B, T>) {
41            self.execute(future)
42        }
43    }
44
45    impl<E, B, T> sealed_client::Sealed<(B, T)> for E
46    where
47        E: Executor<H2ClientFuture<B, T>>,
48        B: http_body::Body + 'static,
49        B::Error: Into<BoxError>,
50        H2ClientFuture<B, T>: Future<Output = ()>,
51        T: AsyncRead + AsyncWrite + Unpin,
52    {
53    }
54
55    mod sealed_client {
56        pub trait Sealed<X> {}
57    }
58}