move remove

This commit is contained in:
nora 2022-09-15 22:01:36 +02:00
parent f3bd42191f
commit 207235037e
7 changed files with 175 additions and 84 deletions

View file

@ -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<HttpRequest> 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

View file

@ -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.

View file

@ -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<Response, Error>
```
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.

View file

@ -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<Req>,
<D::Service as Service<Req>>::Error: Into<crate::BoxError>,
{
pub fn new(discover: D) -> Self {
pub fn new(_: D) -> Self {
todo!()
}
}
@ -45,10 +45,6 @@ where
fn poll_ready(&mut self) -> Poll<Result<(), Self::Error>> {
todo!()
}
fn call(&mut self, request: Req) -> Self::Future {
todo!()
}
}
pub struct PoolDiscoverer<MS, Target, Request>
@ -62,7 +58,7 @@ impl<MS, Target, Request> Stream for PoolDiscoverer<MS, Target, Request>
where
MS: MakeService<Target, Request>,
{
type Item = Result<(Change<usize, DropNotifyService<MS::Service>>), MS::MakeError>;
type Item = Result<Change<usize, DropNotifyService<MS::Service>>, MS::MakeError>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
todo!()
@ -110,10 +106,6 @@ where
fn poll_ready(&mut self) -> Poll<Result<(), Self::Error>> {
todo!()
}
fn call(&mut self, req: Req) -> Self::Future {
todo!()
}
}
pub struct DropNotifyService<Svc> {
@ -141,8 +133,4 @@ impl<Request, Svc: Service<Request>> Service<Request> for DropNotifyService<Svc>
fn poll_ready(&mut self) -> Poll<Result<(), Self::Error>> {
todo!()
}
fn call(&mut self, req: Request) -> Self::Future {
todo!()
}
}

View file

@ -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<Option<Result<Change<Self::Key, Self::Service>, Self::Error>>>);
}
impl<K, S, E, D: ?Sized> Sealed<Change<(), ()>> for D
where
D: TryStream<Ok = Change<K, S>, Error = E>,
K: Eq,
{
}
impl<K, S, E, D: ?Sized> Discover for D
where
D: TryStream<Ok = Change<K, S>, Error = E>,
K: Eq,
{
type Key = K;
type Service = S;
type Error = E;
fn poll_discover(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Option<Result<D::Ok, D::Error>>> {
todo!()
}
}
/// A change in the service set.
#[derive(Debug)]
pub enum Change<K, V> {
Insert(K, V),
Remove(K),
}

View file

@ -1,7 +1,6 @@
// #![allow(warnings)]
pub mod balance;
pub mod discover;
pub mod make;
pub trait Sealed<T> {}
@ -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<K, S, E, D: ?Sized> Sealed<Change<(), ()>> for D
where
D: TryStream<Ok = Change<K, S>, Error = E>,
K: Eq,
{
}
impl<K, S, E, D: ?Sized> Discover for D
where
D: TryStream<Ok = Change<K, S>, Error = E>,
K: Eq,
{
type Key = K;
type Service = S;
type Error = E;
}
pub struct Change<K, V>(K, V);
pub trait Service<Request> {
/// Responses given by the service.
type Response;
@ -30,6 +56,4 @@ pub trait Service<Request> {
type Future: Future<Output = Result<Self::Response, Self::Error>>;
fn poll_ready(&mut self) -> Poll<Result<(), Self::Error>>;
fn call(&mut self, req: Request) -> Self::Future;
}

View file

@ -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<Result<(), Self::Error>> {
todo!()
}
fn call(&mut self, _target: T) -> Self::Future {
todo!()
}
}
pub struct SharedFuture<S> {
@ -52,8 +48,6 @@ pub trait MakeService<Target, Request> {
type Service: Service<Request, Response = Self::Response, Error = Self::Error>;
type MakeError;
type Future;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::MakeError>>;
fn make_service(&mut self, target: Target) -> Self::Future;
}
impl<M, S, Target, Request> 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<Result<(), Self::MakeError>> {
Service::poll_ready(self)
}
fn make_service(&mut self, target: Target) -> Self::Future {
Service::call(self, target)
}
}