#io #async #non-blocking #futures #service

tower

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

13 releases

new 0.4.4 Jan 20, 2021
0.3.1 Jan 18, 2020
0.3.0 Dec 19, 2019
0.3.0-alpha.1a Sep 14, 2019
0.0.1 Dec 23, 2016

#89 in Asynchronous

Download history 24647/week @ 2020-10-02 22529/week @ 2020-10-09 25901/week @ 2020-10-16 28211/week @ 2020-10-23 26850/week @ 2020-10-30 25064/week @ 2020-11-06 29464/week @ 2020-11-13 30068/week @ 2020-11-20 27258/week @ 2020-11-27 31435/week @ 2020-12-04 32860/week @ 2020-12-11 25539/week @ 2020-12-18 16539/week @ 2020-12-25 30352/week @ 2021-01-01 41356/week @ 2021-01-08 36312/week @ 2021-01-15

124,677 downloads per month
Used in 51 crates (23 directly)

MIT license

345KB
6.5K SLoC

Tower

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

Crates.io Documentation Documentation (master) MIT licensed Build Status Discord chat

Overview

Tower aims to make it as easy as possible to build robust networking clients and servers. It is protocol agnostic, but is designed around a request / response pattern. If your protocol is entirely stream based, Tower may not be a good fit.

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 abstraction can be used to model both clients 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 additional 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 function taking a Service of one type and returning a Service of a different type. The ServiceBuilder type is used to add middleware to a service by composing it with multiple multiple Layers.

The Tower Ecosystem

Tower is made up of the following crates:

Since the Service and Layer traits are important integration points for all libraries using Tower, they are kept as stable as possible, and breaking changes are made rarely. Therefore, they are defined in separate crates, tower-service and tower-layer. This crate contains re-exports of those core traits, implementations of commonly-used middleware, and utilities for working with Services and Layers. Finally, the tower-test crate provides tools for testing programs using Tower.

Usage

The various middleware implementations provided by this crate are feature flagged, so that users can only compile the parts of Tower they need. By default, all the optional middleware are disabled.

To get started using all of Tower's optional middleware, add this to your Cargo.toml:

tower = { version = "0.4", features = ["full"] }

Alternatively, you can only enable some features. For example, to enable only the retry and timeout middleware, write:

tower = { version = "0.4", features = ["retry", "timeout"] }

See here for a complete list of all middleware provided by Tower.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tower by you, shall be licensed as MIT, without any additional terms or conditions.

Dependencies

~0.8–2.2MB
~42K SLoC