Skip to main content

IntoHandlerResult

Trait IntoHandlerResult 

Source
pub trait IntoHandlerResult<T: Serialize> {
    // Required method
    fn into_handler_result(self) -> HandlerResult<T>;
}
Expand description

Trait for types that can be converted into a HandlerResult.

This enables handlers to return either Result<T, E> directly (auto-wrapped in Output::Render) or the explicit HandlerResult<T> when fine-grained control is needed (for Output::Silent or Output::Binary).

§Example

use standout_dispatch::{HandlerResult, Output, IntoHandlerResult};

// Direct Result<T, E> is auto-wrapped in Output::Render
fn simple() -> Result<String, anyhow::Error> {
    Ok("hello".to_string())
}
let result: HandlerResult<String> = simple().into_handler_result();
assert!(matches!(result, Ok(Output::Render(_))));

// HandlerResult<T> passes through unchanged
fn explicit() -> HandlerResult<String> {
    Ok(Output::Silent)
}
let result: HandlerResult<String> = explicit().into_handler_result();
assert!(matches!(result, Ok(Output::Silent)));

Required Methods§

Source

fn into_handler_result(self) -> HandlerResult<T>

Convert this type into a HandlerResult<T>.

Implementations on Foreign Types§

Source§

impl<T, E> IntoHandlerResult<T> for Result<T, E>
where T: Serialize, E: Into<Error>,

Implementation for Result<T, E> - auto-wraps successful values in Output::Render.

This is the ergonomic path: handlers can return Result<T, E> directly and the framework wraps it appropriately.

Implementors§

Source§

impl<T: Serialize> IntoHandlerResult<T> for HandlerResult<T>

Implementation for HandlerResult<T> - passes through unchanged.

This is the explicit path: handlers that need Output::Silent or Output::Binary can return HandlerResult<T> directly.