serenade_http_axum/
dispatch.rs1use axum::http::request::Parts;
4use axum::response::Response as AxumResponse;
5use serenade_http::{AsyncHttpKernel, HttpKernel};
6
7use crate::{conversion_error, from_axum, to_axum};
8
9#[must_use]
11pub fn dispatch(kernel: &HttpKernel, parts: &Parts, body: impl AsRef<[u8]>) -> AxumResponse {
12 match from_axum(parts, body) {
13 Ok(serenade) => to_axum(&kernel.handle(serenade)),
14 Err(error) => conversion_error(&error),
15 }
16}
17
18#[must_use]
20pub async fn dispatch_async(
21 kernel: &AsyncHttpKernel,
22 parts: &Parts,
23 body: impl AsRef<[u8]>,
24) -> AxumResponse {
25 match from_axum(parts, body) {
26 Ok(serenade) => to_axum(&kernel.handle(serenade).await),
27 Err(error) => conversion_error(&error),
28 }
29}