Skip to main content

IntoResponse

Trait IntoResponse 

Source
pub trait IntoResponse: IntoResponseBounds {
    // Required method
    fn into_response(self) -> Response;
}
Expand description

Trait for converting types into bot responses

Similar to skyzen’s Responder trait, this allows handlers to return various types that get converted to responses.

§Example

// Return a string directly
async fn ping() -> &'static str {
    "Pong!"
}

// Return a formatted string
async fn greet(user: User) -> String {
    format!("Hello, {}!", user.name)
}

// Return Response for full control
async fn buttons() -> Response {
    Response::text("Click a button:")
        .with_components(vec![...])
}

Required Methods§

Source

fn into_response(self) -> Response

Convert this type into a bot response

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl IntoResponse for &'static str

Source§

impl IntoResponse for ()

Source§

impl IntoResponse for Cow<'static, str>

Source§

impl IntoResponse for File

Source§

impl IntoResponse for PathBuf

Source§

impl IntoResponse for String

Source§

impl<C: Into<String> + IntoResponseBounds> IntoResponse for (File, C)

Source§

impl<C: Into<String> + IntoResponseBounds> IntoResponse for (PathBuf, C)

Source§

impl<T, E> IntoResponse for Result<T, E>
where T: IntoResponse, E: Display + IntoResponseBounds,

Err is rendered to the user as Error: {e}.

Return Response directly when a handler needs to control what a failure looks like, or keep the error type’s Display user-facing.

Source§

impl<T: IntoResponse> IntoResponse for Option<T>

Implementors§