Skip to main content

Status

Struct Status 

Source
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: Code

The gRPC status code.

§message: String

A human-readable description. Percent-encoded on the wire so it can carry arbitrary UTF-8.

§metadata: Metadata

Trailing metadata sent alongside the status.

Implementations§

Source§

impl Status

Source

pub fn new(code: Code, message: impl Into<String>) -> Self

Construct a Status with the given code and message, and empty metadata. The code-named constructors (not_found, internal, …) are usually more convenient.

Source

pub fn ok() -> Self

The success status: code Ok, empty message, empty metadata.

Source

pub fn is_ok(&self) -> bool

Whether this status is the success code.

Source

pub fn with_metadata(self, metadata: Metadata) -> Self

Attach trailing metadata. Carried in the grpc-status trailers alongside grpc-message.

Source

pub fn cancelled(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn unknown(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn invalid_argument(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn deadline_exceeded(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn not_found(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn already_exists(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn permission_denied(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn resource_exhausted(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn failed_precondition(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn aborted(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn out_of_range(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn unimplemented(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn internal(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn unavailable(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn data_loss(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn unauthenticated(message: impl Into<String>) -> Self

Construct a Status with this code and the given message, and empty metadata.

Source

pub fn into_trailers(self) -> Headers

Serialize into a fresh Headers, suitable for use as response trailers. See write_into for the header layout.

Source

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.

Source

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 Clone for Status

Source§

fn clone(&self) -> Status

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Status

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Status

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Status

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Server for T
where T: 'static,

Source§

async fn unary<Req, Resp>( conn: Conn, f: impl AsyncFnOnce(&mut GrpcServerConn<Self>, Req) -> Result<Resp, Status>, ) -> Conn
where Self: Codec<Req> + Codec<Resp>, Req: Send + 'static, Resp: Send + 'static,

Available on crate feature server only.
Unary RPC: read exactly one request, await the user function, emit one response frame followed by grpc-status trailers.
Source§

async fn client_streaming<Resp>( conn: Conn, f: impl AsyncFnOnce(&mut GrpcServerConn<Self>) -> Result<Resp, Status>, ) -> Conn
where Self: Codec<Resp>, Resp: Send + 'static,

Available on crate feature server only.
Client-streaming RPC: hand the user a 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
where Self: Codec<Req> + Codec<Resp>, Req: Send + 'static, Resp: Send + 'static, S: Stream<Item = Result<Resp, Status>> + Send + 'static,

Available on crate feature server only.
Server-streaming RPC: read one request, await the user function for a response 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>, ) -> Conn
where Self: Codec<Req> + Codec<Resp>, Req: Send + 'static, Resp: Send + 'static, R: BidiResponder<Req, Resp>,

Available on crate feature server only.
Bidirectional-streaming RPC — the run-phase prologue. Hand the user a 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.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.