Bug 1716518 - Upgrade tower-service to v0.3.1.

Differential Revision: https://phabricator.services.mozilla.com/D117871

Depends on D117870
This commit is contained in:
Mike Hommey 2021-06-15 09:25:49 +00:00
Родитель 3c5cd06492
Коммит ce7d38e96b
6 изменённых файлов: 101 добавлений и 29 удалений

4
Cargo.lock сгенерированный
Просмотреть файл

@ -5346,9 +5346,9 @@ dependencies = [
[[package]]
name = "tower-service"
version = "0.3.0"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860"
checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"
[[package]]
name = "tracy-rs"

Просмотреть файл

@ -1 +1 @@
{"files":{"CHANGELOG.md":"f27f052f43dce93f155dd4ed266b839bf248362b397c4257d522a03deccd677d","Cargo.toml":"5faca0916e798cd3dc035b976aabdc551e3a470242a0f6a4a2b3260fd4b2afe3","LICENSE":"4249c8e6c5ebb85f97c77e6457c6fafc1066406eb8f1ef61e796fbdc5ff18482","README.md":"7960fa603065260070c6f538f7e521f6829794e823080c29041e30a9c95970d9","src/lib.rs":"35582b17016726fbc69688d20d946143e541855b47e04b9efc65a90baa91d515"},"package":"e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860"}
{"files":{"CHANGELOG.md":"a202a1d257e8b3def187b371f26a47161afae5804040d7ad43d344809d1d1674","Cargo.toml":"09b0ebd19eac7f2185ac817da8d3877dea0725502d1ad1bbb96ea4fdf2621b42","LICENSE":"4249c8e6c5ebb85f97c77e6457c6fafc1066406eb8f1ef61e796fbdc5ff18482","README.md":"da9cb4815bf06e0991df6bf4e9f46272e26115dcc4e2c8f9ffc05e11d486179e","src/lib.rs":"d24ae2a7f7e075372839fddd13f833268d8e9ff8ffa3ca7aa1bf00e18fb57b80"},"package":"360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6"}

8
third_party/rust/tower-service/CHANGELOG.md поставляемый
Просмотреть файл

@ -1,3 +1,11 @@
# Unreleased
# 0.3.1 (November 29, 2019)
- Improve example in `Service` docs. ([#510])
[#510]: https://github.com/tower-rs/tower/pull/510
# 0.3.0 (November 29, 2019)
- Update to `futures 0.3`.

15
third_party/rust/tower-service/Cargo.toml поставляемый
Просмотреть файл

@ -13,16 +13,25 @@
[package]
edition = "2018"
name = "tower-service"
version = "0.3.0"
version = "0.3.1"
authors = ["Tower Maintainers <team@tower-rs.com>"]
description = "Trait representing an asynchronous, request / response based, client or server.\n"
homepage = "https://github.com/tower-rs/tower"
documentation = "https://docs.rs/tower-service/0.3.0"
documentation = "https://docs.rs/tower-service/0.3.1"
readme = "README.md"
categories = ["asynchronous", "network-programming"]
license = "MIT"
repository = "https://github.com/tower-rs/tower"
[dependencies]
[dev-dependencies.futures]
version = "0.3"
[dev-dependencies.http]
version = "0.1"
version = "0.2"
[dev-dependencies.tokio]
version = "1"
[dev-dependencies.tower-layer]
version = "0.3"

26
third_party/rust/tower-service/README.md поставляемый
Просмотреть файл

@ -1,10 +1,30 @@
# Tower Service
The foundational `Service` trait that Tower is based on.
The foundational `Service` trait that [Tower] is based on.
[![Crates.io][crates-badge]][crates-url]
[![Documentation][docs-badge]][docs-url]
[![Documentation (master)][docs-master-badge]][docs-master-url]
[![MIT licensed][mit-badge]][mit-url]
[![Build Status][actions-badge]][actions-url]
[![Discord chat][discord-badge]][discord-url]
[crates-badge]: https://img.shields.io/crates/v/tower-service.svg
[crates-url]: https://crates.io/crates/tower-service
[docs-badge]: https://docs.rs/tower-service/badge.svg
[docs-url]: https://docs.rs/tower-service
[docs-master-badge]: https://img.shields.io/badge/docs-master-blue
[docs-master-url]: https://tower-rs.github.io/tower/tower_service
[mit-badge]: https://img.shields.io/badge/license-MIT-blue.svg
[mit-url]: LICENSE
[actions-badge]: https://github.com/tower-rs/tower/workflows/CI/badge.svg
[actions-url]:https://github.com/tower-rs/tower/actions?query=workflow%3ACI
[discord-badge]: https://img.shields.io/discord/500028886025895936?logo=discord&label=discord&logoColor=white
[discord-url]: https://discord.gg/EeF3cQw
## Overview
The [`Service`] trait provides the foundation upon which Tower is built. It is a
The [`Service`] trait provides the foundation upon which [Tower] is built. It is a
simple, but powerful trait. At its heart, `Service` is just an asynchronous
function of request to response.
@ -24,7 +44,7 @@ By using standardizing the interface, middleware can be created. Middleware
middleware may take actions such as modify the request.
[`Service`]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html
[Tower]: https://crates.io/crates/tower
## License
This project is licensed under the [MIT license](LICENSE).

75
third_party/rust/tower-service/src/lib.rs поставляемый
Просмотреть файл

@ -1,10 +1,11 @@
#![doc(html_root_url = "https://docs.rs/tower-service/0.3.0")]
#![doc(html_root_url = "https://docs.rs/tower-service/0.3.1")]
#![warn(
missing_debug_implementations,
missing_docs,
rust_2018_idioms,
unreachable_pub
)]
#![deny(broken_intra_doc_links)]
//! Definition of the core `Service` trait to Tower
//!
@ -46,7 +47,6 @@ use std::task::{Context, Poll};
/// # use std::task::{Poll, Context};
/// # use std::future::Future;
/// # use tower_service::Service;
///
/// use http::{Request, Response, StatusCode};
///
/// struct HelloWorld;
@ -70,7 +70,7 @@ use std::task::{Context, Poll};
/// .status(StatusCode::OK)
/// .body(body)
/// .expect("Unable to create `http::Response`");
///
///
/// // create a response in a future.
/// let fut = async {
/// Ok(resp)
@ -111,7 +111,7 @@ use std::task::{Context, Poll};
///
/// Take timeouts as an example:
///
/// ```rust,ignore
/// ```rust
/// use tower_service::Service;
/// use tower_layer::Layer;
/// use futures::FutureExt;
@ -119,17 +119,16 @@ use std::task::{Context, Poll};
/// use std::task::{Context, Poll};
/// use std::time::Duration;
/// use std::pin::Pin;
/// use std::fmt;
/// use std::error::Error;
///
///
/// // Our timeout service, which wraps another service and
/// // adds a timeout to its response future.
/// pub struct Timeout<T> {
/// inner: T,
/// timeout: Duration,
/// }
///
/// pub struct TimeoutLayer(Duration);
///
/// pub struct Expired;
///
/// impl<T> Timeout<T> {
/// pub fn new(inner: T, timeout: Duration) -> Timeout<T> {
/// Timeout {
@ -139,48 +138,84 @@ use std::task::{Context, Poll};
/// }
/// }
///
/// // The error returned if processing a request timed out
/// #[derive(Debug)]
/// pub struct Expired;
///
/// impl fmt::Display for Expired {
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
/// write!(f, "expired")
/// }
/// }
///
/// impl Error for Expired {}
///
/// // We can implement `Service` for `Timeout<T>` if `T` is a `Service`
/// impl<T, Request> Service<Request> for Timeout<T>
/// where
/// T: Service<Request>,
/// T::Future: 'static,
/// T::Error: From<Expired> + 'static,
/// T::Response: 'static
/// T::Error: Into<Box<dyn Error + Send + Sync>> + 'static,
/// T::Response: 'static,
/// {
/// // `Timeout` doesn't modify the response type, so we use `T`'s response type
/// type Response = T::Response;
/// type Error = T::Error;
/// // Errors may be either `Expired` if the timeout expired, or the inner service's
/// // `Error` type. Therefore, we return a boxed `dyn Error + Send + Sync` trait object to erase
/// // the error's type.
/// type Error = Box<dyn Error + Send + Sync>;
/// type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
///
/// fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
/// // Our timeout service is ready if the inner service is ready.
/// // This is how backpressure can be propagated through a tree of nested services.
/// self.inner.poll_ready(cx).map_err(Into::into)
/// }
///
/// fn call(&mut self, req: Request) -> Self::Future {
/// let timeout = tokio_timer::delay_for(self.timeout)
/// .map(|_| Err(Self::Error::from(Expired)));
/// // Create a future that completes after `self.timeout`
/// let timeout = tokio::time::sleep(self.timeout);
///
/// let fut = Box::pin(self.inner.call(req));
/// let f = futures::select(fut, timeout)
/// .map(|either| either.factor_first().0);
/// // Call the inner service and get a future that resolves to the response
/// let fut = self.inner.call(req);
///
/// // Wrap those two futures in another future that completes when either one completes
/// //
/// // If the inner service is too slow the `sleep` future will complete first
/// // And an error will be returned and `fut` will be dropped and not polled again
/// //
/// // We have to box the errors so the types match
/// let f = async move {
/// tokio::select! {
/// res = fut => {
/// res.map_err(|err| err.into())
/// },
/// _ = timeout => {
/// Err(Box::new(Expired) as Box<dyn Error + Send + Sync>)
/// },
/// }
/// };
///
/// Box::pin(f)
/// }
/// }
///
/// // A layer for wrapping services in `Timeout`
/// pub struct TimeoutLayer(Duration);
///
/// impl TimeoutLayer {
/// pub fn new(delay: Duration) -> Self {
/// TimeoutLayer(delay)
/// }
/// }
///
/// impl<S> Layer<S> for TimeoutLayer
/// {
/// impl<S> Layer<S> for TimeoutLayer {
/// type Service = Timeout<S>;
///
/// fn layer(&self, service: S) -> Timeout<S> {
/// Timeout::new(service, self.0)
/// }
/// }
///
/// ```
///
/// The above timeout implementation is decoupled from the underlying protocol