Skip to main content

IntoResponse

Trait IntoResponse 

Source
pub trait IntoResponse: Send {
    // 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

Implementations on Foreign Types§

Source§

impl IntoResponse for &'static str

Source§

impl IntoResponse for (File, &'static str)

Source§

impl IntoResponse for (File, String)

Source§

impl IntoResponse for Cow<'static, str>

Source§

impl IntoResponse for ()

Source§

impl IntoResponse for String

Source§

impl IntoResponse for File

Source§

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

Source§

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

Implementors§