feat: introduce typed resp request

This commit is contained in:
mokurin000
2025-07-30 04:27:32 +08:00
parent 5ea8ebbf64
commit dd1bb5fb5c
5 changed files with 87 additions and 7 deletions

View File

@@ -13,7 +13,7 @@ use nyquest::{
r#async::Request,
header::{ACCEPT_ENCODING, CONTENT_ENCODING, EXPECT, USER_AGENT},
};
use serde::Serialize;
use serde::{Deserialize, Serialize};
pub trait MaiVersion {
const AES_KEY: &[u8; 32];
@@ -63,7 +63,7 @@ pub trait MaiVersionExt: MaiVersion {
Ok(req)
}
fn request<D>(
fn request_raw<D>(
client: &AsyncClient,
api: APIMethod,
agent_extra: impl Display,
@@ -79,6 +79,22 @@ pub trait MaiVersionExt: MaiVersion {
Ok(decoded)
}
}
fn request<D, R>(
client: &AsyncClient,
api: APIMethod,
agent_extra: impl Display,
data: D,
) -> impl Future<Output = Result<R, ApiError>>
where
D: Serialize,
R: for<'a> Deserialize<'a>,
{
async {
let raw_data = Self::request_raw(client, api, agent_extra, data).await?;
Ok(serde_json::from_slice(&raw_data)?)
}
}
}
pub struct Sdgb1_40;