Skip to main content

AideResponseFor

Trait AideResponseFor 

Source
pub trait AideResponseFor: IntoResponseWith {
    type Inner;

    // Required method
    fn inferred_response_for(
        ctx: &mut GenContext,
        operation: &mut Operation,
        status: StatusCode,
    ) -> Response;
}
Expand description

Should be implemented for a type to be used as T inside [ApiError<T, _>], for usage with aide.

Required Associated Types§

Required Methods§

Source

fn inferred_response_for( ctx: &mut GenContext, operation: &mut Operation, status: StatusCode, ) -> Response

See aide::OperationOutput::inferred_responses.

§Example
use axum_error_sets::{IntoResponseWith, AideResponseFor};
use axum::response::{IntoResponse, Response};
use http::StatusCode;

struct MyErrorValue(String);

impl IntoResponseWith for MyErrorValue {
    fn into_response_with(self, status: StatusCode) -> Response {
        (status, self.0).into_response()
   }
}

impl AideResponseFor for MyErrorValue {
    type Inner = String;

    fn inferred_response_for(
        _ctx: &mut aide::generate::GenContext,
        _operation: &mut aide::openapi::Operation,
        status: StatusCode,
    ) -> aide::openapi::Response {
        aide::openapi::Response {
            description: format!("Error: {}", status),
            ..Default::default()
        }
    }
}

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§