wx_rust_common/util/http/request_executor.rs
1//! HTTP 请求执行器抽象。
2//!
3//! 对应 Java `me.chanjar.weixin.common.util.http.RequestExecutor`。
4
5use async_trait::async_trait;
6
7use crate::enums::WxType;
8use crate::error::WxErrorException;
9
10/// HTTP 响应处理器(对应 Java `ResponseHandler<T>`)。
11#[async_trait]
12pub trait ResponseHandler<T>: Send + Sync {
13 /// 处理 HTTP 响应。
14 ///
15 /// # 参数
16 /// - `response`:响应结果
17 async fn handle(&self, response: T);
18}
19
20/// HTTP 请求执行器策略。
21///
22/// 对应 Java `RequestExecutor<T, E>` 接口;在 Rust 中以 async trait 表达。
23/// 每个 Java 执行器类(SimpleGet/Post、MediaUpload/Download 等)对应一个
24/// Rust 实现结构体,持有 `reqwest::Client`。
25///
26/// # 类型参数
27/// - `T`:返回值类型
28/// - `E`:请求参数类型
29#[async_trait]
30pub trait RequestExecutor<T, E>: Send + Sync {
31 /// 执行 HTTP 请求。
32 ///
33 /// # 参数
34 /// - `uri`:请求 URI(已含 access_token)
35 /// - `data`:请求数据
36 /// - `wx_type`:微信模块类型
37 ///
38 /// # 返回
39 /// 响应结果。
40 async fn execute(&self, uri: &str, data: E, wx_type: WxType) -> Result<T, WxErrorException>;
41}