pub trait HttpTransport: Send + Sync {
// Required method
fn post_json(&self, url: &str, body: &str) -> Result<(), NotifyError>;
}Expand description
HTTP 传输 trait — 用于解耦 Notifier 与具体 HTTP 库
业务方实现此 trait 注入 reqwest / hyper / etc.,即可让 SlackNotifier 等基于 HTTP 的
通知器投入生产。
§线程安全
实现者必须保证 Send + Sync,因为 Notifier 通常作为单例在多线程下使用。
Required Methods§
Sourcefn post_json(&self, url: &str, body: &str) -> Result<(), NotifyError>
fn post_json(&self, url: &str, body: &str) -> Result<(), NotifyError>
发送 POST 请求,Content-Type: application/json
§参数
url: 目标 URLbody: 请求体(JSON 字符串)
§返回
成功返回 Ok(()),失败返回 NotifyError。
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".