ngx/core/
status.rs

1use core::ffi::c_char;
2use core::fmt;
3use core::ptr;
4
5use crate::ffi::*;
6
7/// Status
8///
9/// Rust native wrapper for NGINX status codes.
10#[derive(Ord, PartialOrd, Eq, PartialEq)]
11pub struct Status(pub ngx_int_t);
12
13impl Status {
14    /// Is this Status equivalent to NGX_OK?
15    pub fn is_ok(&self) -> bool {
16        self == &Status::NGX_OK
17    }
18}
19
20impl fmt::Debug for Status {
21    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22        fmt::Debug::fmt(&self.0, f)
23    }
24}
25
26impl From<Status> for ngx_int_t {
27    fn from(val: Status) -> Self {
28        val.0
29    }
30}
31
32macro_rules! ngx_codes {
33    (
34        $(
35            $(#[$docs:meta])*
36            ($konst:ident);
37        )+
38    ) => {
39        impl Status {
40        $(
41            $(#[$docs])*
42            pub const $konst: Status = Status($konst as ngx_int_t);
43        )+
44
45        }
46    }
47}
48
49ngx_codes! {
50    /// NGX_OK - Operation succeeded.
51    (NGX_OK);
52    /// NGX_ERROR - Operation failed.
53    (NGX_ERROR);
54    /// NGX_AGAIN - Operation incomplete; call the function again.
55    (NGX_AGAIN);
56    /// NGX_BUSY - Resource is not available.
57    (NGX_BUSY);
58    /// NGX_DONE - Operation complete or continued elsewhere. Also used as an alternative success code.
59    (NGX_DONE);
60    /// NGX_DECLINED - Operation rejected, for example, because it is disabled in the configuration.
61    /// This is never an error.
62    (NGX_DECLINED);
63    /// NGX_ABORT - Function was aborted. Also used as an alternative error code.
64    (NGX_ABORT);
65}
66
67/// An error occurred while parsing and validating configuration.
68pub const NGX_CONF_ERROR: *mut c_char = ptr::null_mut::<c_char>().wrapping_offset(-1);
69/// Configuration handler succeeded.
70pub const NGX_CONF_OK: *mut c_char = ptr::null_mut();