Skip to main content

route_util/
http_mailbox.rs

1use crate::mailbox::{MailboxParser, MailboxReq};
2use http_pool::body::VariantBody;
3use http_pool::net_pool::{Pool, Pools};
4use hyper::body::{Bytes, Incoming};
5use hyper::{Request, Response};
6
7/// json解析器
8pub struct JsonMailboxParser;
9
10impl MailboxParser for JsonMailboxParser {
11    type Error = serde_json::Error;
12
13    fn parse(data: Bytes, _zip: Option<String>) -> Result<MailboxReq, Self::Error> {
14        serde_json::from_slice(data.as_ref())
15    }
16}
17
18pub async fn send_to_mailbox<P: Pool>(
19    builder: &kmailbox::Builder,
20    pools: Pools<P>,
21    req: Request<Incoming>,
22) -> Result<(Response<VariantBody>, Option<anyhow::Error>), anyhow::Error> {
23    crate::mailbox::send_to_mailbox::<P, JsonMailboxParser>(builder, pools, req).await
24}