chore: rename ServiceName -> NamedService (#233)

BREAKING CHANGE: Rename `ServiceName` to `NamedService`.
This commit is contained in:
Juan Alvarez
2020-01-13 21:41:24 -05:00
committed by Lucio Franco
parent eba7ec7b32
commit 6ee2ed9b4f
4 changed files with 11 additions and 11 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
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;
pub use pb::test_service_server::TestServiceServer;
@@ -170,7 +170,7 @@ pub struct EchoHeadersSvc<S> {
inner: S,
}
impl<S: ServiceName> ServiceName for EchoHeadersSvc<S> {
impl<S: NamedService> NamedService for EchoHeadersSvc<S> {
const NAME: &'static str = S::NAME;
}
+1 -1
View File
@@ -188,7 +188,7 @@ fn generate_transport(
let service_name = syn::LitStr::new(service_name, proc_macro2::Span::call_site());
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;
}
}
+2 -2
View File
@@ -63,7 +63,7 @@
//! # unimplemented!()
//! # }
//! # }
//! # impl tonic::transport::ServiceName for Svc {
//! # impl tonic::transport::NamedService for Svc {
//! # const NAME: &'static str = "some_svc";
//! # }
//! # let my_svc = Svc;
@@ -97,7 +97,7 @@ mod tls;
pub use self::channel::{Channel, Endpoint};
pub use self::error::Error;
#[doc(inline)]
pub use self::server::{Server, ServiceName};
pub use self::server::{NamedService, Server};
pub use self::tls::{Certificate, Identity};
pub use hyper::{Body, Uri};
+6 -6
View File
@@ -73,7 +73,7 @@ pub struct Router<A, B> {
/// A trait to provide a static reference to the service's
/// name. This is used for routing service's within the router.
pub trait ServiceName {
pub trait NamedService {
/// The `Service-Name` as described [here].
///
/// [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>
where
S: Service<Request<Body>, Response = Response<BoxBody>>
+ ServiceName
+ NamedService
+ Clone
+ Send
+ 'static,
@@ -277,14 +277,14 @@ impl<S> Router<S, Unimplemented> {
pub(crate) fn new(server: Server, svc: S) -> Self
where
S: Service<Request<Body>, Response = Response<BoxBody>>
+ ServiceName
+ NamedService
+ Clone
+ Send
+ 'static,
S::Future: Send + 'static,
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 pred = move |req: &Request<Body>| {
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>>>
where
S: Service<Request<Body>, Response = Response<BoxBody>>
+ ServiceName
+ NamedService
+ Clone
+ Send
+ 'static,
@@ -320,7 +320,7 @@ where
{
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 pred = move |req: &Request<Body>| {
let path = req.uri().path();