feat: add GrpcMethod extension into request for client (#1275)

* feat: add GrpcMethod extension into request for client

* refactor: change GrpcMethod fields into private and expose methods instead

* refactor: hide GrpcMethod::new in doc

---------

Co-authored-by: Lucio Franco <[email protected]>
This commit is contained in:
林玮 (Jade Lin)
2023-02-23 10:06:45 +00:00
committed by GitHub
co-authored by Lucio Franco
parent 1547f968b4
commit 7a6b20d8ef
9 changed files with 207 additions and 85 deletions
+1
View File
@@ -11,6 +11,7 @@ pub use std::task::{Context, Poll};
pub use tower_service::Service;
pub type StdError = Box<dyn std::error::Error + Send + Sync + 'static>;
pub use crate::codec::{CompressionEncoding, EnabledCompressionEncodings};
pub use crate::extensions::GrpcMethod;
pub use crate::service::interceptor::InterceptedService;
pub use bytes::Bytes;
pub use http;
+24
View File
@@ -71,3 +71,27 @@ impl fmt::Debug for Extensions {
f.debug_struct("Extensions").finish()
}
}
/// A gRPC Method info extension.
#[derive(Debug)]
pub struct GrpcMethod {
service: &'static str,
method: &'static str,
}
impl GrpcMethod {
/// Create a new `GrpcMethod` extension.
#[doc(hidden)]
pub fn new(service: &'static str, method: &'static str) -> Self {
Self { service, method }
}
/// gRPC service name
pub fn service(&self) -> &str {
&self.service
}
/// gRPC method name
pub fn method(&self) -> &str {
&self.method
}
}
+1 -1
View File
@@ -111,7 +111,7 @@ pub use async_trait::async_trait;
#[doc(inline)]
pub use codec::Streaming;
pub use extensions::Extensions;
pub use extensions::{Extensions, GrpcMethod};
pub use request::{IntoRequest, IntoStreamingRequest, Request};
pub use response::Response;
pub use status::{Code, Status};