feat: abstract method to perform action

This commit is contained in:
mokurin000
2025-07-30 03:20:21 +08:00
parent 6ee009715d
commit 1a281e0cc7
7 changed files with 59 additions and 15 deletions

View File

@@ -9,7 +9,7 @@ pub mod model;
mod error;
pub use error::ApiError;
use nyquest::{
Body,
AsyncClient, Body,
r#async::Request,
header::{ACCEPT_ENCODING, CONTENT_ENCODING, EXPECT, USER_AGENT},
};
@@ -62,6 +62,23 @@ pub trait MaiVersionExt: MaiVersion {
Ok(req)
}
fn request<D>(
client: &AsyncClient,
api: APIMethod,
agent_extra: impl Display,
data: D,
) -> impl Future<Output = Result<Vec<u8>, ApiError>>
where
D: Serialize,
{
async {
let req = Self::api_request(api, agent_extra, data)?;
let data = client.request(req).await?.bytes().await?;
let decoded = Self::decode(data)?;
Ok(decoded)
}
}
}
pub struct Sdgb1_40;