From 207235037ede041778c42d658a39389ac0a9b600 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Thu, 15 Sep 2022 22:01:36 +0200 Subject: [PATCH] move remove --- tower/tower-service/CHANGELOG.md | 63 ++++++++++++++++++++++++++++++++ tower/tower-service/LICENSE | 25 +++++++++++++ tower/tower-service/README.md | 56 ++++++++++++++++++++++++++++ tower/tower/src/balance.rs | 18 ++------- tower/tower/src/discover.rs | 51 -------------------------- tower/tower/src/lib.rs | 30 +++++++++++++-- tower/tower/src/make.rs | 16 +------- 7 files changed, 175 insertions(+), 84 deletions(-) create mode 100644 tower/tower-service/CHANGELOG.md create mode 100644 tower/tower-service/LICENSE create mode 100644 tower/tower-service/README.md delete mode 100644 tower/tower/src/discover.rs diff --git a/tower/tower-service/CHANGELOG.md b/tower/tower-service/CHANGELOG.md new file mode 100644 index 0000000..8bc4f65 --- /dev/null +++ b/tower/tower-service/CHANGELOG.md @@ -0,0 +1,63 @@ +# Unreleased + +- None + +# 0.3.2 (June 17, 2022) + +## Added + +- **docs**: Clarify subtlety around cloning and readiness in the `Service` docs + ([#548]) +- **docs**: Clarify details around shared resource consumption in `poll_ready()` + ([#662]) + + +[#548]: https://github.com/tower-rs/tower/pull/548 +[#662]: https://github.com/tower-rs/tower/pull/662 + + +# 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`. +- Update documentation for `std::future::Future`. + +# 0.3.0-alpha.2 (September 30, 2019) + +- Documentation fixes. + +# 0.3.0-alpha.1 (Aug 20, 2019) + +* Switch to `std::future::Future` + +# 0.2.0 (Dec 12, 2018) + +* Change `Service`'s `Request` associated type to be a generic instead. + * Before: + + ```rust + impl Service for Client { + type Request = HttpRequest; + type Response = HttpResponse; + // ... + } + ``` + * After: + + ```rust + impl Service for Client { + type Response = HttpResponse; + // ... + } + ``` +* Remove `NewService`, use `tower_util::MakeService` instead. +* Remove `Service::ready` and `Ready`, use `tower_util::ServiceExt` instead. + +# 0.1.0 (Aug 9, 2018) + +* Initial release diff --git a/tower/tower-service/LICENSE b/tower/tower-service/LICENSE new file mode 100644 index 0000000..b980cac --- /dev/null +++ b/tower/tower-service/LICENSE @@ -0,0 +1,25 @@ +Copyright (c) 2019 Tower Contributors + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/tower/tower-service/README.md b/tower/tower-service/README.md new file mode 100644 index 0000000..3f2766d --- /dev/null +++ b/tower/tower-service/README.md @@ -0,0 +1,56 @@ +# Tower Service + +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 +simple, but powerful trait. At its heart, `Service` is just an asynchronous +function of request to response. + +``` +async fn(Request) -> Result +``` + +Implementations of `Service` take a request, the type of which varies per +protocol, and returns a future representing the eventual completion or failure +of the response. + +Services are used to represent both clients and servers. An *instance* of +`Service` is used through a client; a server *implements* `Service`. + +By using standardizing the interface, middleware can be created. Middleware +*implement* `Service` by passing the request to another `Service`. The +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). + +### 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. diff --git a/tower/tower/src/balance.rs b/tower/tower/src/balance.rs index 9774425..f4775ec 100644 --- a/tower/tower/src/balance.rs +++ b/tower/tower/src/balance.rs @@ -1,7 +1,7 @@ -use crate::discover::{Change, Discover}; use crate::load::Load; use crate::make::MakeService; use crate::Service; +use crate::{Change, Discover}; use futures_core::Stream; use futures_util::future::{self}; use std::hash::Hash; @@ -21,7 +21,7 @@ where D::Service: Service, >::Error: Into, { - pub fn new(discover: D) -> Self { + pub fn new(_: D) -> Self { todo!() } } @@ -45,10 +45,6 @@ where fn poll_ready(&mut self) -> Poll> { todo!() } - - fn call(&mut self, request: Req) -> Self::Future { - todo!() - } } pub struct PoolDiscoverer @@ -62,7 +58,7 @@ impl Stream for PoolDiscoverer where MS: MakeService, { - type Item = Result<(Change>), MS::MakeError>; + type Item = Result>, MS::MakeError>; fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { todo!() @@ -110,10 +106,6 @@ where fn poll_ready(&mut self) -> Poll> { todo!() } - - fn call(&mut self, req: Req) -> Self::Future { - todo!() - } } pub struct DropNotifyService { @@ -141,8 +133,4 @@ impl> Service for DropNotifyService fn poll_ready(&mut self) -> Poll> { todo!() } - - fn call(&mut self, req: Request) -> Self::Future { - todo!() - } } diff --git a/tower/tower/src/discover.rs b/tower/tower/src/discover.rs deleted file mode 100644 index 9cfa2a3..0000000 --- a/tower/tower/src/discover.rs +++ /dev/null @@ -1,51 +0,0 @@ -use crate::Sealed; -use futures_core::TryStream; -use std::{ - pin::Pin, - task::{Context, Poll}, -}; - -mod error { - pub enum Never {} -} - -pub trait Discover { - type Key: Eq; - type Service; - type Error; - fn poll_discover( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> (Poll, Self::Error>>>); -} - -impl Sealed> for D -where - D: TryStream, Error = E>, - K: Eq, -{ -} - -impl Discover for D -where - D: TryStream, Error = E>, - K: Eq, -{ - type Key = K; - type Service = S; - type Error = E; - - fn poll_discover( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll>> { - todo!() - } -} - -/// A change in the service set. -#[derive(Debug)] -pub enum Change { - Insert(K, V), - Remove(K), -} diff --git a/tower/tower/src/lib.rs b/tower/tower/src/lib.rs index b08f550..f6b743d 100644 --- a/tower/tower/src/lib.rs +++ b/tower/tower/src/lib.rs @@ -1,7 +1,6 @@ // #![allow(warnings)] pub mod balance; -pub mod discover; pub mod make; pub trait Sealed {} @@ -19,6 +18,33 @@ mod load { use std::future::Future; use std::task::Poll; +use futures_core::TryStream; + +pub trait Discover { + type Key: Eq; + type Service; + type Error; +} + +impl Sealed> for D +where + D: TryStream, Error = E>, + K: Eq, +{ +} + +impl Discover for D +where + D: TryStream, Error = E>, + K: Eq, +{ + type Key = K; + type Service = S; + type Error = E; +} + +pub struct Change(K, V); + pub trait Service { /// Responses given by the service. type Response; @@ -30,6 +56,4 @@ pub trait Service { type Future: Future>; fn poll_ready(&mut self) -> Poll>; - - fn call(&mut self, req: Request) -> Self::Future; } diff --git a/tower/tower/src/make.rs b/tower/tower/src/make.rs index 73b6af4..bac5875 100644 --- a/tower/tower/src/make.rs +++ b/tower/tower/src/make.rs @@ -2,7 +2,7 @@ use crate::Sealed; use crate::Service; -use std::task::{Context, Poll}; +use std::task::Poll; use std::convert::Infallible; @@ -21,10 +21,6 @@ where fn poll_ready(&mut self) -> Poll> { todo!() } - - fn call(&mut self, _target: T) -> Self::Future { - todo!() - } } pub struct SharedFuture { @@ -52,8 +48,6 @@ pub trait MakeService { type Service: Service; type MakeError; type Future; - fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll>; - fn make_service(&mut self, target: Target) -> Self::Future; } impl Sealed<(Target, Request)> for M @@ -73,12 +67,4 @@ where type Service = S; type MakeError = M::Error; type Future = M::Future; - - fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { - Service::poll_ready(self) - } - - fn make_service(&mut self, target: Target) -> Self::Future { - Service::call(self, target) - } }