Skip to main content

Response

Trait Response 

Source
pub trait Response: Sized + __Classify {
    type Payload;

    // Required methods
    fn ok(payload: Self::Payload) -> Self;
    fn err(msg: impl Into<String>) -> Self;
    fn is_ok(&self) -> bool;
    fn into_result(self) -> Result<Self::Payload, String>;

    // Provided methods
    fn is_err(&self) -> bool { ... }
    fn from_result(result: Result<Self::Payload, String>) -> Self { ... }
    fn error_msg(&self) -> Option<String> { ... }
    fn then<J>(self, jig: J) -> J::Out
       where J: Jig<Self>,
             J::Out: Response { ... }
}
Expand description

An outbound message produced by a pipeline.

Types implementing this trait wrap a Result so that downstream jigs can short-circuit on error.

Required Associated Types§

Source

type Payload

The payload carried by a successful response.

Required Methods§

Source

fn ok(payload: Self::Payload) -> Self

Construct a successful response.

Source

fn err(msg: impl Into<String>) -> Self

Construct an errored response from a message.

Source

fn is_ok(&self) -> bool

Returns true if this response carries a value.

Source

fn into_result(self) -> Result<Self::Payload, String>

Convert into an owned Result.

§Errors

Returns Err with the error message when the response carries an error.

Provided Methods§

Source

fn is_err(&self) -> bool

Returns true if this response carries an error.

Source

fn from_result(result: Result<Self::Payload, String>) -> Self

Wrap a Result into a response.

Source

fn error_msg(&self) -> Option<String>

Non-consuming access to the error message, if this is an error.

Source

fn then<J>(self, jig: J) -> J::Out
where J: Jig<Self>, J::Out: Response,

Append a Response -> Response jig. The jig always runs, including on errored responses, so finalizers see every outcome.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§