Struct axum_tonic::GrpcStatus
source · pub struct GrpcStatus(pub Status);
Expand description
A simple wrapper around a tonic::Status
usable in axum middleware.
§Example
use axum::{middleware::{Next, from_fn}, response::Response, Router};
use axum_tonic::GrpcStatus;
use hyper::Request;
async fn tonic_middleware<B>(
req: Request<B>,
next: Next<B>
) -> Result<Response, GrpcStatus> {
if is_auth(&req) {
Ok(next.run(req).await)
} else {
Err(
tonic::Status::permission_denied("Not authenticated").into()
)
}
}
fn is_auth<B>(req: &Request<B>) -> bool {
true // or other logic
}
let router: Router<()> = Router::new()
.layer(from_fn(tonic_middleware));
Tuple Fields§
§0: Status
Methods from Deref<Target = Status>§
sourcepub fn metadata(&self) -> &MetadataMap
pub fn metadata(&self) -> &MetadataMap
Get a reference to the custom metadata.
sourcepub fn metadata_mut(&mut self) -> &mut MetadataMap
pub fn metadata_mut(&mut self) -> &mut MetadataMap
Get a mutable reference to the custom metadata.
Trait Implementations§
source§impl Debug for GrpcStatus
impl Debug for GrpcStatus
source§impl Deref for GrpcStatus
impl Deref for GrpcStatus
source§impl DerefMut for GrpcStatus
impl DerefMut for GrpcStatus
source§impl From<Status> for GrpcStatus
impl From<Status> for GrpcStatus
source§impl IntoResponse for GrpcStatus
impl IntoResponse for GrpcStatus
source§fn into_response(self) -> Response
fn into_response(self) -> Response
Create a response.
Auto Trait Implementations§
impl !RefUnwindSafe for GrpcStatus
impl Send for GrpcStatus
impl Sync for GrpcStatus
impl Unpin for GrpcStatus
impl !UnwindSafe for GrpcStatus
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request