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