| bounds.rs |
Trait aliases
Traits in this module ease setting bounds and usually automatically
implemented by implementing another trait. |
4344 |
- |
| io.rs |
|
15840 |
- |
| mod.rs |
Runtime components
This module provides traits and types that allow hyper to be runtime-agnostic.
By abstracting over async runtimes, hyper can work with different executors, timers, and IO transports.
The main components in this module are:
- **Executors**: Traits for spawning and running futures, enabling integration with any async runtime.
- **Timers**: Abstractions for sleeping and scheduling tasks, allowing time-based operations to be runtime-independent.
- **IO Transports**: Traits for asynchronous reading and writing, so hyper can work with various IO backends.
By implementing these traits, you can customize how hyper interacts with your chosen runtime environment.
To learn more, [check out the runtime guide](https://hyper.rs/guides/1/init/runtime/). |
1573 |
- |
| timer.rs |
Provides a timer trait with timer-like functions
Example using tokio timer:
```rust
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
time::{Duration, Instant},
};
use pin_project_lite::pin_project;
use hyper::rt::{Timer, Sleep};
#[derive(Clone, Debug)]
pub struct TokioTimer;
impl Timer for TokioTimer {
fn sleep(&self, duration: Duration) -> Pin<Box<dyn Sleep>> {
Box::pin(TokioSleep {
inner: tokio::time::sleep(duration),
})
}
fn sleep_until(&self, deadline: Instant) -> Pin<Box<dyn Sleep>> {
Box::pin(TokioSleep {
inner: tokio::time::sleep_until(deadline.into()),
})
}
fn reset(&self, sleep: &mut Pin<Box<dyn Sleep>>, new_deadline: Instant) {
if let Some(sleep) = sleep.as_mut().downcast_mut_pin::<TokioSleep>() {
sleep.reset(new_deadline.into())
}
}
}
pin_project! {
pub(crate) struct TokioSleep {
#[pin]
pub(crate) inner: tokio::time::Sleep,
}
}
impl Future for TokioSleep {
type Output = ();
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
self.project().inner.poll(cx)
}
}
impl Sleep for TokioSleep {}
impl TokioSleep {
pub fn reset(self: Pin<&mut Self>, deadline: Instant) {
self.project().inner.as_mut().reset(deadline.into());
}
}
``` |
3591 |
- |