Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename ServiceName -> NamedService #233

Merged
merged 1 commit into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions interop/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tonic-build/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tonic/src/transport/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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};

Expand Down
12 changes: 6 additions & 6 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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();
Expand Down