Skip to main content

neco_server_core/
status.rs

1/// Minimal HTTP status code wrapper.
2#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub struct StatusCode(u16);
4
5impl StatusCode {
6    /// 200 OK
7    pub const OK: Self = Self(200);
8    /// 400 Bad Request
9    pub const BAD_REQUEST: Self = Self(400);
10    /// 401 Unauthorized
11    pub const UNAUTHORIZED: Self = Self(401);
12    /// 404 Not Found
13    pub const NOT_FOUND: Self = Self(404);
14    /// 405 Method Not Allowed
15    pub const METHOD_NOT_ALLOWED: Self = Self(405);
16    /// 500 Internal Server Error
17    pub const INTERNAL_SERVER_ERROR: Self = Self(500);
18
19    /// Creates a status code wrapper from a raw value.
20    pub const fn from_u16(value: u16) -> Self {
21        Self(value)
22    }
23
24    /// Returns the raw numeric value.
25    pub const fn as_u16(self) -> u16 {
26        self.0
27    }
28}