pub struct Status {
pub code: Code,
pub message: String,
pub metadata: Metadata,
}Expand description
The outcome of an RPC: a Code, a human-readable message, and any
trailing Metadata.
This is both the error type returned from service methods and the value
parsed back out of a response’s grpc-status trailers. It implements
std::error::Error, so ? works in any method returning Result<_, Status>. Build one with new or a code-named constructor
such as not_found.
Fields§
§code: CodeThe gRPC status code.
message: StringA human-readable description. Percent-encoded on the wire so it can carry arbitrary UTF-8.
metadata: MetadataTrailing metadata sent alongside the status.
Implementations§
Source§impl Status
impl Status
Sourcepub fn with_metadata(self, metadata: Metadata) -> Self
pub fn with_metadata(self, metadata: Metadata) -> Self
Attach trailing metadata. Carried in the grpc-status trailers
alongside grpc-message.
Sourcepub fn cancelled(message: impl Into<String>) -> Self
pub fn cancelled(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn unknown(message: impl Into<String>) -> Self
pub fn unknown(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn invalid_argument(message: impl Into<String>) -> Self
pub fn invalid_argument(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn deadline_exceeded(message: impl Into<String>) -> Self
pub fn deadline_exceeded(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn not_found(message: impl Into<String>) -> Self
pub fn not_found(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn already_exists(message: impl Into<String>) -> Self
pub fn already_exists(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn permission_denied(message: impl Into<String>) -> Self
pub fn permission_denied(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn resource_exhausted(message: impl Into<String>) -> Self
pub fn resource_exhausted(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn failed_precondition(message: impl Into<String>) -> Self
pub fn failed_precondition(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn aborted(message: impl Into<String>) -> Self
pub fn aborted(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn out_of_range(message: impl Into<String>) -> Self
pub fn out_of_range(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn unimplemented(message: impl Into<String>) -> Self
pub fn unimplemented(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn internal(message: impl Into<String>) -> Self
pub fn internal(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn data_loss(message: impl Into<String>) -> Self
pub fn data_loss(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn unauthenticated(message: impl Into<String>) -> Self
pub fn unauthenticated(message: impl Into<String>) -> Self
Construct a Status with this code and the given message, and
empty metadata.
Sourcepub fn into_trailers(self) -> Headers
pub fn into_trailers(self) -> Headers
Serialize into a fresh Headers, suitable for use as response
trailers. See write_into for the header layout.
Sourcepub fn write_into(&self, headers: &mut Headers)
pub fn write_into(&self, headers: &mut Headers)
Write grpc-status (and, when non-empty, the percent-encoded
grpc-message) plus any trailing metadata into headers.
Sourcepub fn from_trailers(headers: &Headers) -> Result<(), Self>
pub fn from_trailers(headers: &Headers) -> Result<(), Self>
Read a Status from response trailers (or trailer-only response headers).
Returns Ok(()) for grpc-status: 0, Err(Status) otherwise.
Missing grpc-status is treated as Unknown per spec. On the Err
path the returned Status carries any custom trailing metadata
extracted from the same headers.
Trait Implementations§
Source§impl Error for Status
impl Error for Status
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for Status
impl RefUnwindSafe for Status
impl Send for Status
impl Sync for Status
impl Unpin for Status
impl UnsafeUnpin for Status
impl UnwindSafe for Status
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Server for Twhere
T: 'static,
impl<T> Server for Twhere
T: 'static,
Source§async fn unary<Req, Resp>(
conn: Conn,
f: impl AsyncFnOnce(&mut GrpcServerConn<Self>, Req) -> Result<Resp, Status>,
) -> Conn
async fn unary<Req, Resp>( conn: Conn, f: impl AsyncFnOnce(&mut GrpcServerConn<Self>, Req) -> Result<Resp, Status>, ) -> Conn
server only.grpc-status trailers.Source§async fn client_streaming<Resp>(
conn: Conn,
f: impl AsyncFnOnce(&mut GrpcServerConn<Self>) -> Result<Resp, Status>,
) -> Conn
async fn client_streaming<Resp>( conn: Conn, f: impl AsyncFnOnce(&mut GrpcServerConn<Self>) -> Result<Resp, Status>, ) -> Conn
server only.GrpcServerConn from which they read
the request stream (conn.requests::<Req>()); emit the single response
frame and grpc-status trailers.Source§async fn server_streaming<Req, Resp, S>(
conn: Conn,
f: impl AsyncFnOnce(&mut GrpcServerConn<Self>, Req) -> Result<S, Status>,
) -> Conn
async fn server_streaming<Req, Resp, S>( conn: Conn, f: impl AsyncFnOnce(&mut GrpcServerConn<Self>, Req) -> Result<S, Status>, ) -> Conn
server only.Stream, then frame each item lazily into the response body
with grpc-status trailers derived from how the stream ended.Source§async fn bidi<Req, Resp, R>(
conn: Conn,
prologue: impl AsyncFnOnce(&mut GrpcServerConn<Self>) -> Result<R, Status>,
) -> Connwhere
Self: Codec<Req> + Codec<Resp>,
Req: Send + 'static,
Resp: Send + 'static,
R: BidiResponder<Req, Resp>,
async fn bidi<Req, Resp, R>(
conn: Conn,
prologue: impl AsyncFnOnce(&mut GrpcServerConn<Self>) -> Result<R, Status>,
) -> Connwhere
Self: Codec<Req> + Codec<Resp>,
Req: Send + 'static,
Resp: Send + 'static,
R: BidiResponder<Req, Resp>,
server only.GrpcServerConn from which they may read early request messages (to decide
response headers) and set initial metadata, then return a
BidiResponder that drives the read-while-write loop after the head is
flushed. Returning Err(Status) rejects before the flush (trailers-only,
no upgrade). See crate::server::bidi for the seam mechanics.