Skip to content

Latest commit

 

History

History
9 lines (5 loc) · 1.08 KB

tower.md

File metadata and controls

9 lines (5 loc) · 1.08 KB

Crate tower

Tower is a library of modular and reusable components for building robust networking clients and servers.

Tower provides a simple core abstraction, the Service trait, which represents an asynchronous function taking a request and returning either a response or an error. This astraction can be used to model both client and servers.

Generic components, like timeouts, rate limiting, and load balancing, can be modeled as Services that wrap some inner service and apply additional behavior before or after the inner service is called. This allows implementing these components in a protocol-agnostic, composable way. Typically, such services are referred to as middleware.

An additinal abstraction, the Layer trait, is used to compose middleware with Services. If a Service can be thought of as an asynchronous function from a request type to a response type, a Layer is a functrion taking a Service of one typr and returning a Service of a different type. The ServiceBuilder type is used to add middleware to a service by composing it with multiple Layers.