From 7a2a611b20a1dda7571ca8736dc9e3e627bfbc91 Mon Sep 17 00:00:00 2001 From: Joe Dahlquist Date: Wed, 24 Aug 2022 11:06:23 -0700 Subject: [PATCH] expose Extensions::into_http and Status::from_error --- tonic/src/extensions.rs | 4 +++- tonic/src/status.rs | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/tonic/src/extensions.rs b/tonic/src/extensions.rs index aef1f7ebc..470b84af9 100644 --- a/tonic/src/extensions.rs +++ b/tonic/src/extensions.rs @@ -7,6 +7,7 @@ use std::fmt; /// /// [`Interceptor`]: crate::service::Interceptor /// [`Request`]: crate::Request +#[derive(Default)] pub struct Extensions { inner: http::Extensions, } @@ -58,8 +59,9 @@ impl Extensions { Self { inner: http } } + /// Convert to `http::Extensions` and consume self. #[inline] - pub(crate) fn into_http(self) -> http::Extensions { + pub fn into_http(self) -> http::Extensions { self.inner } } diff --git a/tonic/src/status.rs b/tonic/src/status.rs index 9db79301f..2aef8bf41 100644 --- a/tonic/src/status.rs +++ b/tonic/src/status.rs @@ -310,8 +310,12 @@ impl Status { Self::from_error(err.into()) } + /// Create a `Status` from various types of `Error`. + /// + /// Inspects the error source chain for recognizable errors, including statuses, HTTP2, and + /// hyper, and attempts to maps them to a `Status`, or else returns an Unknown `Status`. #[cfg_attr(not(feature = "transport"), allow(dead_code))] - pub(crate) fn from_error(err: Box) -> Status { + pub fn from_error(err: Box) -> Status { Status::try_from_error(err).unwrap_or_else(|err| { let mut status = Status::new(Code::Unknown, err.to_string()); status.source = Some(err);