| 1 | //! Runtime components |
| 2 | //! |
| 3 | //! The traits and types within this module are used to allow plugging in |
| 4 | //! runtime types. These include: |
| 5 | //! |
| 6 | //! - Executors |
| 7 | //! - Timers |
| 8 | //! - IO transports |
| 9 | |
| 10 | pub mod bounds; |
| 11 | mod io; |
| 12 | mod timer; |
| 13 | |
| 14 | pub use self::io::{Read, ReadBuf, ReadBufCursor, Write}; |
| 15 | pub use self::timer::{Sleep, Timer}; |
| 16 | |
| 17 | /// An executor of futures. |
| 18 | /// |
| 19 | /// This trait allows Hyper to abstract over async runtimes. Implement this trait for your own type. |
| 20 | /// |
| 21 | /// # Example |
| 22 | /// |
| 23 | /// ``` |
| 24 | /// # use hyper::rt::Executor; |
| 25 | /// # use std::future::Future; |
| 26 | /// #[derive(Clone)] |
| 27 | /// struct TokioExecutor; |
| 28 | /// |
| 29 | /// impl<F> Executor<F> for TokioExecutor |
| 30 | /// where |
| 31 | /// F: Future + Send + 'static, |
| 32 | /// F::Output: Send + 'static, |
| 33 | /// { |
| 34 | /// fn execute(&self, future: F) { |
| 35 | /// tokio::spawn(future); |
| 36 | /// } |
| 37 | /// } |
| 38 | /// ``` |
| 39 | pub trait Executor<Fut> { |
| 40 | /// Place the future into the executor to be run. |
| 41 | fn execute(&self, fut: Fut); |
| 42 | } |
| 43 | |