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

Expose Extensions::into_http and Status::from_error #1067

Merged
merged 1 commit into from
Aug 24, 2022
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: 3 additions & 1 deletion tonic/src/extensions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::fmt;
///
/// [`Interceptor`]: crate::service::Interceptor
/// [`Request`]: crate::Request
#[derive(Default)]
pub struct Extensions {
inner: http::Extensions,
}
Expand Down Expand Up @@ -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
}
}
Expand Down
6 changes: 5 additions & 1 deletion tonic/src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn Error + Send + Sync + 'static>) -> Status {
pub fn from_error(err: Box<dyn Error + Send + Sync + 'static>) -> Status {
Status::try_from_error(err).unwrap_or_else(|err| {
let mut status = Status::new(Code::Unknown, err.to_string());
status.source = Some(err);
Expand Down