Struct api_resp::ApiResp

source ·
pub struct ApiResp { /* private fields */ }
Expand description

API接口响应数据结构。

Implementations§

构造一个成功的响应对象。

Arguments
  • data: 业务数据。

returns: ApiResp

Examples
use api_resp::ApiResp;
use serde_json::json;
let data = vec![1,1,3,5];
let resp = ApiResp::success(json!(data));

构造一个成功的简单响应对象,不带任何消息。

returns: ApiResp 返回成功响应。

Examples
use api_resp::ApiResp;
let resp = ApiResp::suc();

构造一个失败的响应对象。

Arguments
  • code: 失败代码。根据具体的业务接口约定取值列表。
  • message: 失败信息。

returns: ApiResp

Examples
use api_resp::ApiResp;
let resp = ApiResp::fail(-1, String::from("查询信息失败,原因:..."));

Trait Implementations§

Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.