Skip to main content

Crate zincio_hyper

Crate zincio_hyper 

Source
Expand description

A compatibility layer for using hyper with the zincio async runtime.

This crate provides the necessary adapters to run hyper-based HTTP servers and clients on top of zincio instead of tokio. It implements the traits required by hyper’s runtime abstraction:

  • ZincioExecutor: An executor that spawns tasks on the zincio runtime using zincio::spawn.
  • ZincioTimer: A timer that uses zincio::time::sleep for delay operations.
  • ZincioIo: A wrapper type that adapts zincio’s I/O types to implement hyper’s Read and Write traits, and also implements tokio’s AsyncRead and AsyncWrite traits for compatibility.

§Overview

This crate enables hyper to work with zincio by implementing hyper’s runtime traits (Executor, Timer, Read, Write, Sleep) in terms of zincio primitives.

§Executor

The ZincioExecutor type implements hyper::rt::Executor by spawning futures onto the zincio runtime via zincio::spawn.

§Timer

The ZincioTimer type implements hyper::rt::Timer by converting sleep requests into zincio::time::sleep futures wrapped in a compatible type.

§I/O Adapters

The ZincioIo<T> wrapper adapts any type that implements tokio::io::AsyncRead and tokio::io::AsyncWrite to work with hyper’s I/O traits. It also implements the reverse conversion, allowing hyper’s I/O types to be used with tokio-style async functions.

§Implementation notes

  • The ZincioIo wrapper uses Pin<Box<T>> internally to support the trait implementations required by hyper and tokio.
  • The ZincioSleep type (internal) implements both hyper::rt::Sleep and std::future::Future to bridge the two runtimes’ sleep abstractions.
  • Timer handles are properly cancelled when ZincioSleep is dropped to avoid resource leaks.

Structs§

ZincioExecutor
An executor that spawns tasks onto the zincio runtime.
ZincioIo
A wrapper type that adapts I/O types for use with hyper and tokio.
ZincioTimer
A timer that uses zincio’s time utilities for sleep operations.