rocket_json_response/
json_response_code.rs

1/// The code of your JSON response.
2pub trait JSONResponseCode {
3    /// Assume the code **0** means **OK**. You can define other codes by yourself.
4    /// This method will be called for one time when the response is being triggered. You can do something (perhaps keep a log?) at the moment.
5    fn get_code(&self) -> i32;
6}
7
8impl JSONResponseCode for i8 {
9    #[inline]
10    fn get_code(&self) -> i32 {
11        i32::from(*self)
12    }
13}
14
15impl JSONResponseCode for i16 {
16    #[inline]
17    fn get_code(&self) -> i32 {
18        i32::from(*self)
19    }
20}
21
22impl JSONResponseCode for i32 {
23    #[inline]
24    fn get_code(&self) -> i32 {
25        *self
26    }
27}
28
29impl JSONResponseCode for u8 {
30    #[inline]
31    fn get_code(&self) -> i32 {
32        i32::from(*self)
33    }
34}
35
36impl JSONResponseCode for u16 {
37    #[inline]
38    fn get_code(&self) -> i32 {
39        i32::from(*self)
40    }
41}
42
43impl JSONResponseCode for u32 {
44    #[inline]
45    fn get_code(&self) -> i32 {
46        *self as i32
47    }
48}