Skip to content

Commit

Permalink
feat: expose minimal sufficient set of symbols via ::prelude::*
Browse files Browse the repository at this point in the history
  • Loading branch information
xeioex committed Jan 29, 2025
1 parent 4ee19c0 commit 5c57b8b
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 22 deletions.
8 changes: 4 additions & 4 deletions examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use std::sync::Arc;
use std::time::Instant;

use ngx::core;
use ngx::core::prelude::*;
use ngx::ffi::{
ngx_array_push, ngx_command_t, ngx_conf_t, ngx_cycle, ngx_event_t, ngx_http_core_module, ngx_http_core_run_phases,
ngx_http_handler_pt, ngx_http_module_t, ngx_http_phases_NGX_HTTP_ACCESS_PHASE, ngx_http_request_t, ngx_int_t,
ngx_module_t, ngx_posted_events, ngx_queue_s, ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1, NGX_HTTP_LOC_CONF,
NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_MODULE,
ngx_array_push, ngx_http_core_module, ngx_http_core_run_phases, ngx_http_phases_NGX_HTTP_ACCESS_PHASE,
ngx_posted_events, ngx_queue_s,
};
use ngx::http::prelude::*;
use ngx::http::{self, HTTPModule, MergeConfigError};
use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string};
use tokio::runtime::Runtime;
Expand Down
8 changes: 3 additions & 5 deletions examples/awssig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ use std::ptr::addr_of;

use http::HeaderMap;
use ngx::core;
use ngx::ffi::{
ngx_array_push, ngx_command_t, ngx_conf_t, ngx_http_core_module, ngx_http_handler_pt, ngx_http_module_t,
ngx_http_phases_NGX_HTTP_PRECONTENT_PHASE, ngx_int_t, ngx_module_t, ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1,
NGX_HTTP_LOC_CONF, NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF,
};
use ngx::core::prelude::*;
use ngx::ffi::{ngx_array_push, ngx_http_phases_NGX_HTTP_PRECONTENT_PHASE};
use ngx::http::prelude::*;
use ngx::http::*;
use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string};

Expand Down
8 changes: 3 additions & 5 deletions examples/curl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ use std::ffi::{c_char, c_void};
use std::ptr::addr_of;

use ngx::core;
use ngx::ffi::{
ngx_array_push, ngx_command_t, ngx_conf_t, ngx_http_core_module, ngx_http_handler_pt, ngx_http_module_t,
ngx_http_phases_NGX_HTTP_ACCESS_PHASE, ngx_int_t, ngx_module_t, ngx_str_t, ngx_uint_t, NGX_CONF_TAKE1,
NGX_HTTP_LOC_CONF, NGX_HTTP_LOC_CONF_OFFSET, NGX_HTTP_MODULE,
};
use ngx::core::prelude::*;
use ngx::ffi::{ngx_array_push, ngx_http_phases_NGX_HTTP_ACCESS_PHASE};
use ngx::http::prelude::*;
use ngx::http::{self, HTTPModule, MergeConfigError};
use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string};

Expand Down
7 changes: 4 additions & 3 deletions examples/httporigdst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use std::ffi::{c_int, c_void};
use std::ptr::addr_of;

use ngx::core;
use ngx::core::prelude::*;
use ngx::ffi::{
in_port_t, ngx_conf_t, ngx_connection_local_sockaddr, ngx_http_add_variable, ngx_http_module_t,
ngx_http_variable_t, ngx_inet_get_port, ngx_int_t, ngx_module_t, ngx_sock_ntop, ngx_str_t, ngx_uint_t,
ngx_variable_value_t, sockaddr, sockaddr_storage, INET_ADDRSTRLEN, NGX_HTTP_MODULE,
in_port_t, ngx_conf_t, ngx_connection_local_sockaddr, ngx_inet_get_port, ngx_sock_ntop, sockaddr, sockaddr_storage,
INET_ADDRSTRLEN,
};
use ngx::http::prelude::*;
use ngx::http::{self, HTTPModule};
use ngx::{http_variable_get, ngx_http_null_variable, ngx_log_debug_http, ngx_null_string, ngx_string};

Expand Down
10 changes: 5 additions & 5 deletions examples/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ use std::mem;
use std::ptr::addr_of;
use std::slice;

use ngx::core::prelude::*;
use ngx::core::{Pool, Status};
use ngx::ffi::{
ngx_atoi, ngx_command_t, ngx_conf_t, ngx_connection_t, ngx_event_free_peer_pt, ngx_event_get_peer_pt,
ngx_http_module_t, ngx_http_upstream_init_peer_pt, ngx_http_upstream_init_pt, ngx_http_upstream_init_round_robin,
ngx_http_upstream_module, ngx_http_upstream_srv_conf_t, ngx_http_upstream_t, ngx_int_t, ngx_module_t,
ngx_peer_connection_t, ngx_str_t, ngx_uint_t, NGX_CONF_NOARGS, NGX_CONF_TAKE1, NGX_CONF_UNSET, NGX_ERROR,
NGX_HTTP_MODULE, NGX_HTTP_SRV_CONF_OFFSET, NGX_HTTP_UPS_CONF, NGX_LOG_EMERG,
ngx_atoi, ngx_event_free_peer_pt, ngx_event_get_peer_pt, ngx_http_upstream_init_peer_pt, ngx_http_upstream_init_pt,
ngx_http_upstream_init_round_robin, ngx_http_upstream_module, ngx_http_upstream_srv_conf_t, ngx_http_upstream_t,
ngx_peer_connection_t, NGX_ERROR,
};
use ngx::http::prelude::*;
use ngx::http::{
ngx_http_conf_get_module_srv_conf, ngx_http_conf_upstream_srv_conf_immutable,
ngx_http_conf_upstream_srv_conf_mutable, HTTPModule, Merge, MergeConfigError, Request,
Expand Down
4 changes: 4 additions & 0 deletions src/core/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
mod buffer;
mod pool;
/// The prelude module.
///
/// This module provides common constants and types that are used in NGINX modules.
pub mod prelude;
mod status;
mod string;

Expand Down
40 changes: 40 additions & 0 deletions src/core/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
pub use crate::ffi::ngx_command_t;
pub use crate::ffi::ngx_conf_t;
pub use crate::ffi::ngx_connection_t;
pub use crate::ffi::ngx_event_t;
pub use crate::ffi::ngx_int_t;
pub use crate::ffi::ngx_module_t;
pub use crate::ffi::ngx_str_t;
pub use crate::ffi::ngx_uint_t;
pub use crate::ffi::ngx_variable_value_t;

pub use crate::ffi::NGX_LOG_ALERT;
pub use crate::ffi::NGX_LOG_CRIT;
pub use crate::ffi::NGX_LOG_DEBUG;
pub use crate::ffi::NGX_LOG_EMERG;
pub use crate::ffi::NGX_LOG_ERR;
pub use crate::ffi::NGX_LOG_INFO;
pub use crate::ffi::NGX_LOG_NOTICE;
pub use crate::ffi::NGX_LOG_WARN;

pub use crate::ffi::NGX_ANY_CONF;
pub use crate::ffi::NGX_CONF_1MORE;
pub use crate::ffi::NGX_CONF_2MORE;
pub use crate::ffi::NGX_CONF_ANY;
pub use crate::ffi::NGX_CONF_ARGS_NUMBER;
pub use crate::ffi::NGX_CONF_BLOCK;
pub use crate::ffi::NGX_CONF_FLAG;
pub use crate::ffi::NGX_CONF_NOARGS;
pub use crate::ffi::NGX_CONF_TAKE1;
pub use crate::ffi::NGX_CONF_TAKE2;
pub use crate::ffi::NGX_CONF_TAKE3;
pub use crate::ffi::NGX_CONF_TAKE4;
pub use crate::ffi::NGX_CONF_TAKE5;
pub use crate::ffi::NGX_CONF_TAKE6;
pub use crate::ffi::NGX_CONF_TAKE7;
pub use crate::ffi::NGX_CONF_UNSET;
pub use crate::ffi::NGX_DIRECT_CONF;
pub use crate::ffi::NGX_MAIN_CONF;

pub use crate::ffi::ngx_cycle;
pub use crate::ffi::ngx_posted_events;
4 changes: 4 additions & 0 deletions src/http/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
mod conf;
mod module;
/// The prelude module.
///
/// This module provides common constants and types that are used in NGINX http modules.
pub mod prelude;
mod request;
mod status;
mod upstream;
Expand Down
23 changes: 23 additions & 0 deletions src/http/prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
pub use crate::ffi::ngx_http_handler_pt;
pub use crate::ffi::ngx_http_module_t;
pub use crate::ffi::ngx_http_request_t;
pub use crate::ffi::ngx_http_variable_t;
pub use crate::ffi::ngx_http_variable_value_t;

pub use crate::ffi::NGX_HTTP_MODULE;

pub use crate::ffi::NGX_HTTP_LIF_CONF;
pub use crate::ffi::NGX_HTTP_LMT_CONF;
pub use crate::ffi::NGX_HTTP_LOC_CONF;
pub use crate::ffi::NGX_HTTP_MAIN_CONF;
pub use crate::ffi::NGX_HTTP_SIF_CONF;
pub use crate::ffi::NGX_HTTP_SRV_CONF;
pub use crate::ffi::NGX_HTTP_UPS_CONF;

pub use crate::ffi::NGX_HTTP_LOC_CONF_OFFSET;
pub use crate::ffi::NGX_HTTP_MAIN_CONF_OFFSET;
pub use crate::ffi::NGX_HTTP_SRV_CONF_OFFSET;

pub use crate::ffi::ngx_http_core_module;

pub use crate::ffi::ngx_http_add_variable;

0 comments on commit 5c57b8b

Please sign in to comment.