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§
Sourcefn into_response(self) -> Response
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
impl IntoResponse for &'static str
fn into_response(self) -> Response
Source§impl IntoResponse for ()
impl IntoResponse for ()
fn into_response(self) -> Response
Source§impl IntoResponse for Cow<'static, str>
impl IntoResponse for Cow<'static, str>
fn into_response(self) -> Response
Source§impl IntoResponse for File
impl IntoResponse for File
fn into_response(self) -> Response
Source§impl IntoResponse for PathBuf
impl IntoResponse for PathBuf
fn into_response(self) -> Response
Source§impl IntoResponse for String
impl IntoResponse for String
fn into_response(self) -> Response
Source§impl<C: Into<String> + IntoResponseBounds> IntoResponse for (File, C)
impl<C: Into<String> + IntoResponseBounds> IntoResponse for (File, C)
fn into_response(self) -> Response
Source§impl<C: Into<String> + IntoResponseBounds> IntoResponse for (PathBuf, C)
impl<C: Into<String> + IntoResponseBounds> IntoResponse for (PathBuf, C)
fn into_response(self) -> Response
Source§impl<T, E> IntoResponse for Result<T, E>where
T: IntoResponse,
E: Display + IntoResponseBounds,
Err is rendered to the user as Error: {e}.
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.