endpoint_libs/libs/error_code.rs
1use serde::*;
2
3/// `ErrorCode` is a wrapper around `u32` that represents an error code.
4#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
5pub struct ErrorCode {
6 /// The error code (e.g. `100400` for BadRequest).
7 code: u32,
8}
9
10impl ErrorCode {
11 /// Create a new `ErrorCode` from a `u32`.
12 pub fn new(code: u32) -> Self {
13 Self { code }
14 }
15
16 /// Get the `ErrorCode` as a `u32`.
17 /// Just returns the code field.
18 pub fn to_u32(self) -> u32 {
19 self.code
20 }
21
22 /// Getter for the `ErrorCode` code field.
23 pub fn code(self) -> u32 {
24 self.to_u32()
25 }
26}