Import optimization
Opened this issue · 0 comments
bavshin-f5 commented
Dmitry has noted that the amount of imports required for even the smallest module example is overwhelming.
We can approach this from several directions:
- Expose a minimal sufficient set of symbols via
ngx::core::prelude::*
andngx::http::prelude::*
- Use enums and
bitflags
as much as possible.
E.g. wrappingNGX_CONF_...
withbitflags
would save a few imports and remove noisyas ngx_uint_t
casts. - Reduce boilerplate code. For example,
would remove a couple of imports that are never necessary in the code and reduce amount of copy-paste needed to get started.
#[no_mangle] #[used] pub static mut ngx_http_example_module: ngx_module_t = ngx_module_t { ctx: std::ptr::addr_of!(NGX_HTTP_EXAMPLE_MODULE_CTX) as _, // Safety: nginx does not modify module.commands. commands: NGX_HTTP_EXAMPLE_COMMANDS.as_ptr().cast_mut(), type_: NGX_HTTP_MODULE as _ .. NGX_RS_MODULE_V1 }