1#[derive(Debug, Clone)]
2pub struct Resp<T> {
3 pub code: i32,
4 pub msg: String,
5 pub data: Option<T>,
6}
7
8impl<T> Resp<T> {
9 pub fn new(code: i32, msg: &str, data: Option<T>) -> Self {
10 Resp {
11 code: code,
12 msg: msg.to_string(),
13 data: data,
14 }
15 }
16
17 pub fn success(msg: &str, data: Option<T>) -> Self {
18 Resp {
19 code: 1,
20 msg: msg.to_string(),
21 data: data,
22 }
23 }
24
25 pub fn success_with_msg(msg: &str) -> Self {
26 Resp {
27 code: 1,
28 msg: msg.to_string(),
29 data: None,
30 }
31 }
32
33 pub fn fail(msg: &str, data: Option<T>) -> Self {
34 Resp {
35 code: 0,
36 msg: msg.to_string(),
37 data: data,
38 }
39 }
40
41 pub fn fail_with_msg(msg: &str) -> Self {
42 Resp {
43 code: 0,
44 msg: msg.to_string(),
45 data: None,
46 }
47 }
48}