Tower
Modular, reusable middleware components for Rust async services such as timeouts, retries and limits.
Official Documentation ↗tower 0.5 / Rust 1.70+. Check the official docs for the latest API surface.Installation
cargo add towerMethods
No methods match this filter.
Overview
Tower provides reusable middleware called layers for async services. Timeouts, retries, rate limiting, concurrency limits and tracing compose without modifying the underlying service.
Core Methods
Build a stack with ServiceBuilder, add layers in order, and call the service. ServiceExt::oneshot invokes a service once, and load-shed or buffer layers manage pressure.
Usage Notes
Layer order matters: place buffering before rate limiting and tracing outermost for visibility. Reuse standard layers instead of hand-rolling cross-cutting logic.
Common Pitfalls
Incorrect layer order changes semantics, for example rate limiting before buffering behaves differently. oneshot consumes the service, so clone when needed. Some layers require the service error type to satisfy bounds.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://docs.rs/tower/latest/tower/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:53:02.766Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Crate tower Crate tower Copy item path Source Expand description async fn(Request) -> Result<Response, Error> § Overview Tower is a library of modular and reusable components for building robust networking clients and servers. (https://docs.rs/tower/latest/tower/)
FAQ
- What is a Tower Service?
- A trait for an async request-response function that can be composed. Layers are middleware built with this trait, so they stack without changing your business code.
- How does buffering fit in?
- BufferLayer decouples the caller from back-pressure by queueing requests, which is often needed before applying a load-shedding or rate-limiting layer.
- Is Tower tied to hyper?
- Tower is generic over services and used widely with hyper, axum and tonic. It is not limited to a specific HTTP stack.
Report a problem with this API docOpens a pre-filled issue on GitHub.