Make some functionality of Status public (#1256)

* Make some functionality of Status public

Signed-off-by: Nick Cameron <nrc@ncameron.org>

* Update tonic/src/status.rs

---------

Signed-off-by: Nick Cameron <nrc@ncameron.org>
Co-authored-by: Lucio Franco <luciofranco14@gmail.com>
This commit is contained in:
Nick Cameron
2023-02-13 15:29:19 +00:00
committed by GitHub
parent b301013d58
commit 7c0e9c853c
+16 -2
View File
@@ -325,7 +325,14 @@ impl Status {
})
}
pub(crate) fn try_from_error(
/// Create a `Status` from various types of `Error`.
///
/// Returns the error if a status could not be created.
///
/// # Downcast stability
/// This function does not provide any stability guarantees around how it will downcast errors into
/// status codes.
pub fn try_from_error(
err: Box<dyn Error + Send + Sync + 'static>,
) -> Result<Status, Box<dyn Error + Send + Sync + 'static>> {
let err = match err.downcast::<Status>() {
@@ -501,7 +508,8 @@ impl Status {
Ok(header_map)
}
pub(crate) fn add_header(&self, header_map: &mut HeaderMap) -> Result<(), Self> {
/// Add headers from this `Status` into `header_map`.
pub fn add_header(&self, header_map: &mut HeaderMap) -> Result<(), Self> {
header_map.extend(self.metadata.clone().into_sanitized_headers());
header_map.insert(GRPC_STATUS_HEADER_CODE, self.code.to_header_value());
@@ -555,6 +563,12 @@ impl Status {
}
}
/// Add a source error to this status.
pub fn set_source(&mut self, source: Arc<dyn Error + Send + Sync + 'static>) -> &mut Status {
self.source = Some(source);
self
}
#[allow(clippy::wrong_self_convention)]
/// Build an `http::Response` from the given `Status`.
pub fn to_http(self) -> http::Response<BoxBody> {