hyper/rt/
mod.rs

1//! Runtime components
2//!
3//! This module provides traits and types that allow hyper to be runtime-agnostic.
4//! By abstracting over async runtimes, hyper can work with different executors, timers, and IO transports.
5//!
6//! The main components in this module are:
7//!
8//! - **Executors**: Traits for spawning and running futures, enabling integration with any async runtime.
9//! - **Timers**: Abstractions for sleeping and scheduling tasks, allowing time-based operations to be runtime-independent.
10//! - **IO Transports**: Traits for asynchronous reading and writing, so hyper can work with various IO backends.
11//!
12//! By implementing these traits, you can customize how hyper interacts with your chosen runtime environment.
13//!
14//! To learn more, [check out the runtime guide](https://hyper.rs/guides/1/init/runtime/).
15
16pub mod bounds;
17mod io;
18mod timer;
19
20pub use self::io::{Read, ReadBuf, ReadBufCursor, Write};
21pub use self::timer::{Sleep, Timer};
22
23/// An executor of futures.
24///
25/// This trait allows Hyper to abstract over async runtimes. Implement this trait for your own type.
26///
27/// # Example
28///
29/// ```
30/// # use hyper::rt::Executor;
31/// # use std::future::Future;
32/// #[derive(Clone)]
33/// struct TokioExecutor;
34///
35/// impl<F> Executor<F> for TokioExecutor
36/// where
37///     F: Future + Send + 'static,
38///     F::Output: Send + 'static,
39/// {
40///     fn execute(&self, future: F) {
41///         tokio::spawn(future);
42///     }
43/// }
44/// ```
45pub trait Executor<Fut> {
46    /// Place the future into the executor to be run.
47    fn execute(&self, fut: Fut);
48}