Skip to content

Commit 9ba3184

Browse files
committed
refactor(client,service): remove tower_service::Service where possible
1 parent b026e3c commit 9ba3184

File tree

6 files changed

+9
-134
lines changed

6 files changed

+9
-134
lines changed

examples/service_struct_impl.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ impl Service<Request<Body>> for Svc {
2727
type Error = hyper::Error;
2828
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
2929

30-
fn poll_ready(&mut self, _: &mut Context) -> Poll<Result<(), Self::Error>> {
31-
Poll::Ready(Ok(()))
32-
}
33-
3430
fn call(&mut self, req: Request<Body>) -> Self::Future {
3531
fn mk_response(s: String) -> Result<Response<Body>, hyper::Error> {
3632
Ok(Response::builder().body(Body::from(s)).unwrap())
@@ -64,10 +60,6 @@ impl<T> Service<T> for MakeSvc {
6460
type Error = hyper::Error;
6561
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send>>;
6662

67-
fn poll_ready(&mut self, _: &mut Context) -> Poll<Result<(), Self::Error>> {
68-
Poll::Ready(Ok(()))
69-
}
70-
7163
fn call(&mut self, _: T) -> Self::Future {
7264
let counter = self.counter.clone();
7365
let fut = async move { Ok(Svc { counter }) };

examples/tower_client.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

examples/tower_server.rs

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/client/conn/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ use futures_util::future::{self, Either, FutureExt as _};
6767
use httparse::ParserConfig;
6868
use pin_project_lite::pin_project;
6969
use tokio::io::{AsyncRead, AsyncWrite};
70-
use tower_service::Service;
7170
use tracing::{debug, trace};
7271

7372
use super::dispatch;
@@ -83,6 +82,7 @@ use crate::rt::Executor;
8382
#[cfg(feature = "http1")]
8483
use crate::upgrade::Upgraded;
8584
use crate::{Body, Request, Response};
85+
use crate::service::Service;
8686

8787
#[cfg(feature = "http1")]
8888
pub mod http1;
@@ -352,10 +352,6 @@ where
352352
type Error = crate::Error;
353353
type Future = ResponseFuture;
354354

355-
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
356-
self.poll_ready(cx)
357-
}
358-
359355
fn call(&mut self, req: Request<B>) -> Self::Future {
360356
self.send_request(req)
361357
}

src/service/util.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::fmt;
33
use std::marker::PhantomData;
44

55
use crate::body::HttpBody;
6-
use crate::common::{task, Future, Poll};
6+
use crate::common::Future;
7+
use crate::service::Service;
78
use crate::{Request, Response};
89

910
/// Create a `Service` from a function.
@@ -41,8 +42,7 @@ pub struct ServiceFn<F, R> {
4142
_req: PhantomData<fn(R)>,
4243
}
4344

44-
impl<F, ReqBody, Ret, ResBody, E> tower_service::Service<crate::Request<ReqBody>>
45-
for ServiceFn<F, ReqBody>
45+
impl<F, ReqBody, Ret, ResBody, E> Service<crate::Request<ReqBody>> for ServiceFn<F, ReqBody>
4646
where
4747
F: FnMut(Request<ReqBody>) -> Ret,
4848
ReqBody: HttpBody,
@@ -54,10 +54,6 @@ where
5454
type Error = E;
5555
type Future = Ret;
5656

57-
fn poll_ready(&mut self, _cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
58-
Poll::Ready(Ok(()))
59-
}
60-
6157
fn call(&mut self, req: Request<ReqBody>) -> Self::Future {
6258
(self.f)(req)
6359
}

tests/server.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use hyper::body::HttpBody as _;
2828
use hyper::client::Client;
2929
use hyper::server::conn::Http;
3030
use hyper::server::Server;
31-
use hyper::service::{make_service_fn, service_fn};
31+
use hyper::service::{make_service_fn, service_fn, Service};
3232
use hyper::{Body, Request, Response, StatusCode, Version};
3333

3434
mod support;
@@ -2335,7 +2335,7 @@ fn http2_body_user_error_sends_reset_reason() {
23352335

23362336
struct Http2ReadyErrorSvc;
23372337

2338-
impl tower_service::Service<Request<Body>> for Http2ReadyErrorSvc {
2338+
impl Service<Request<Body>> for Http2ReadyErrorSvc {
23392339
type Response = Response<Body>;
23402340
type Error = h2::Error;
23412341
type Future = Box<
@@ -2345,12 +2345,6 @@ impl tower_service::Service<Request<Body>> for Http2ReadyErrorSvc {
23452345
+ Unpin,
23462346
>;
23472347

2348-
fn poll_ready(&mut self, _: &mut std::task::Context<'_>) -> Poll<Result<(), Self::Error>> {
2349-
Poll::Ready(Err::<(), _>(h2::Error::from(
2350-
h2::Reason::INADEQUATE_SECURITY,
2351-
)))
2352-
}
2353-
23542348
fn call(&mut self, _: hyper::Request<Body>) -> Self::Future {
23552349
unreachable!("poll_ready error should have shutdown conn");
23562350
}
@@ -2798,15 +2792,11 @@ enum Msg {
27982792
End,
27992793
}
28002794

2801-
impl tower_service::Service<Request<Body>> for TestService {
2795+
impl Service<Request<Body>> for TestService {
28022796
type Response = Response<ReplyBody>;
28032797
type Error = BoxError;
28042798
type Future = BoxFuture;
28052799

2806-
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
2807-
Ok(()).into()
2808-
}
2809-
28102800
fn call(&mut self, mut req: Request<Body>) -> Self::Future {
28112801
let tx = self.tx.clone();
28122802
let replies = self.reply.clone();
@@ -2865,22 +2855,18 @@ const HELLO: &str = "hello";
28652855

28662856
struct HelloWorld;
28672857

2868-
impl tower_service::Service<Request<Body>> for HelloWorld {
2858+
impl Service<Request<Body>> for HelloWorld {
28692859
type Response = Response<Body>;
28702860
type Error = hyper::Error;
28712861
type Future = future::Ready<Result<Response<Body>, Self::Error>>;
28722862

2873-
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
2874-
Ok(()).into()
2875-
}
2876-
28772863
fn call(&mut self, _req: Request<Body>) -> Self::Future {
28782864
let response = Response::new(HELLO.into());
28792865
future::ok(response)
28802866
}
28812867
}
28822868

2883-
fn unreachable_service() -> impl tower_service::Service<
2869+
fn unreachable_service() -> impl Service<
28842870
http::Request<hyper::Body>,
28852871
Response = http::Response<ReplyBody>,
28862872
Error = BoxError,

0 commit comments

Comments
 (0)