chore: rename ServiceName -> NamedService (#233)
BREAKING CHANGE: Rename `ServiceName` to `NamedService`.
This commit is contained in:
committed by
Lucio Franco
parent
eba7ec7b32
commit
6ee2ed9b4f
@@ -7,7 +7,7 @@ use std::future::Future;
|
|||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use tonic::{body::BoxBody, transport::ServiceName, Code, Request, Response, Status};
|
use tonic::{body::BoxBody, transport::NamedService, Code, Request, Response, Status};
|
||||||
use tower::Service;
|
use tower::Service;
|
||||||
|
|
||||||
pub use pb::test_service_server::TestServiceServer;
|
pub use pb::test_service_server::TestServiceServer;
|
||||||
@@ -170,7 +170,7 @@ pub struct EchoHeadersSvc<S> {
|
|||||||
inner: S,
|
inner: S,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: ServiceName> ServiceName for EchoHeadersSvc<S> {
|
impl<S: NamedService> NamedService for EchoHeadersSvc<S> {
|
||||||
const NAME: &'static str = S::NAME;
|
const NAME: &'static str = S::NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ fn generate_transport(
|
|||||||
let service_name = syn::LitStr::new(service_name, proc_macro2::Span::call_site());
|
let service_name = syn::LitStr::new(service_name, proc_macro2::Span::call_site());
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl<T: #server_trait> tonic::transport::ServiceName for #server_service<T> {
|
impl<T: #server_trait> tonic::transport::NamedService for #server_service<T> {
|
||||||
const NAME: &'static str = #service_name;
|
const NAME: &'static str = #service_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@
|
|||||||
//! # unimplemented!()
|
//! # unimplemented!()
|
||||||
//! # }
|
//! # }
|
||||||
//! # }
|
//! # }
|
||||||
//! # impl tonic::transport::ServiceName for Svc {
|
//! # impl tonic::transport::NamedService for Svc {
|
||||||
//! # const NAME: &'static str = "some_svc";
|
//! # const NAME: &'static str = "some_svc";
|
||||||
//! # }
|
//! # }
|
||||||
//! # let my_svc = Svc;
|
//! # let my_svc = Svc;
|
||||||
@@ -97,7 +97,7 @@ mod tls;
|
|||||||
pub use self::channel::{Channel, Endpoint};
|
pub use self::channel::{Channel, Endpoint};
|
||||||
pub use self::error::Error;
|
pub use self::error::Error;
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use self::server::{Server, ServiceName};
|
pub use self::server::{NamedService, Server};
|
||||||
pub use self::tls::{Certificate, Identity};
|
pub use self::tls::{Certificate, Identity};
|
||||||
pub use hyper::{Body, Uri};
|
pub use hyper::{Body, Uri};
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ pub struct Router<A, B> {
|
|||||||
|
|
||||||
/// A trait to provide a static reference to the service's
|
/// A trait to provide a static reference to the service's
|
||||||
/// name. This is used for routing service's within the router.
|
/// name. This is used for routing service's within the router.
|
||||||
pub trait ServiceName {
|
pub trait NamedService {
|
||||||
/// The `Service-Name` as described [here].
|
/// The `Service-Name` as described [here].
|
||||||
///
|
///
|
||||||
/// [here]: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests
|
/// [here]: https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests
|
||||||
@@ -211,7 +211,7 @@ impl Server {
|
|||||||
pub fn add_service<S>(&mut self, svc: S) -> Router<S, Unimplemented>
|
pub fn add_service<S>(&mut self, svc: S) -> Router<S, Unimplemented>
|
||||||
where
|
where
|
||||||
S: Service<Request<Body>, Response = Response<BoxBody>>
|
S: Service<Request<Body>, Response = Response<BoxBody>>
|
||||||
+ ServiceName
|
+ NamedService
|
||||||
+ Clone
|
+ Clone
|
||||||
+ Send
|
+ Send
|
||||||
+ 'static,
|
+ 'static,
|
||||||
@@ -277,14 +277,14 @@ impl<S> Router<S, Unimplemented> {
|
|||||||
pub(crate) fn new(server: Server, svc: S) -> Self
|
pub(crate) fn new(server: Server, svc: S) -> Self
|
||||||
where
|
where
|
||||||
S: Service<Request<Body>, Response = Response<BoxBody>>
|
S: Service<Request<Body>, Response = Response<BoxBody>>
|
||||||
+ ServiceName
|
+ NamedService
|
||||||
+ Clone
|
+ Clone
|
||||||
+ Send
|
+ Send
|
||||||
+ 'static,
|
+ 'static,
|
||||||
S::Future: Send + 'static,
|
S::Future: Send + 'static,
|
||||||
S::Error: Into<crate::Error> + Send,
|
S::Error: Into<crate::Error> + Send,
|
||||||
{
|
{
|
||||||
let svc_name = <S as ServiceName>::NAME;
|
let svc_name = <S as NamedService>::NAME;
|
||||||
let svc_route = format!("/{}", svc_name);
|
let svc_route = format!("/{}", svc_name);
|
||||||
let pred = move |req: &Request<Body>| {
|
let pred = move |req: &Request<Body>| {
|
||||||
let path = req.uri().path();
|
let path = req.uri().path();
|
||||||
@@ -311,7 +311,7 @@ where
|
|||||||
pub fn add_service<S>(self, svc: S) -> Router<S, Or<A, B, Request<Body>>>
|
pub fn add_service<S>(self, svc: S) -> Router<S, Or<A, B, Request<Body>>>
|
||||||
where
|
where
|
||||||
S: Service<Request<Body>, Response = Response<BoxBody>>
|
S: Service<Request<Body>, Response = Response<BoxBody>>
|
||||||
+ ServiceName
|
+ NamedService
|
||||||
+ Clone
|
+ Clone
|
||||||
+ Send
|
+ Send
|
||||||
+ 'static,
|
+ 'static,
|
||||||
@@ -320,7 +320,7 @@ where
|
|||||||
{
|
{
|
||||||
let Self { routes, server } = self;
|
let Self { routes, server } = self;
|
||||||
|
|
||||||
let svc_name = <S as ServiceName>::NAME;
|
let svc_name = <S as NamedService>::NAME;
|
||||||
let svc_route = format!("/{}", svc_name);
|
let svc_route = format!("/{}", svc_name);
|
||||||
let pred = move |req: &Request<Body>| {
|
let pred = move |req: &Request<Body>| {
|
||||||
let path = req.uri().path();
|
let path = req.uri().path();
|
||||||
|
|||||||
Reference in New Issue
Block a user