Skip to main content

TypedServiceResult

Trait TypedServiceResult 

Source
pub trait TypedServiceResult: Send + Sync {
    // Required methods
    fn message(&self) -> &str;
    fn code(&self) -> u16;
    fn response_type(&self) -> ResponseType;
    fn serialize(&self) -> Result<String, Error>;

    // Provided method
    fn data_json(&self) -> Option<Value> { ... }
}
Expand description

Renderable handler result: message, HTTP status, content type, and body serializer. Implemented by ServiceResult, GenericTypedResult, and ErrorResult, so handlers can return them as Box<dyn TypedServiceResult> for mixed payload shapes.

Required Methods§

Source

fn message(&self) -> &str

Human-readable message carried by the result.

Source

fn code(&self) -> u16

HTTP status code used for the response.

Source

fn response_type(&self) -> ResponseType

Content type used for the Content-Type header.

Source

fn serialize(&self) -> Result<String, Error>

Renders the response body; I/O or shape errors surface as serde_json::Error.

Provided Methods§

Source

fn data_json(&self) -> Option<Value>

Returns the payload as JSON when representable; defaults to None.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§