bpi_rs/response.rs
1use crate::err::error::BpiError;
2use serde::{ Deserialize, Serialize };
3
4#[derive(Debug, Serialize, Clone, Deserialize)]
5pub struct BpiResponse<T> {
6 /// 返回值 0:成功
7 #[serde(default)]
8 pub code: i32,
9
10 #[serde(alias = "result")]
11 pub data: Option<T>,
12
13 /// 错误信息,默认为0
14 #[serde(default)]
15 pub message: String,
16
17 /// 状态, 部分接口需要
18 #[serde(default)]
19 pub status: bool,
20}
21
22impl<T> BpiResponse<T> {
23 pub fn into_data(self) -> Result<T, BpiError> {
24 self.data.ok_or(BpiError::missing_data())
25 }
26}