Skip to content

Import optimization #107

Description

@bavshin-f5

Dmitry has noted that the amount of imports required for even the smallest module example is overwhelming.

We can approach this from several directions:

  1. Expose a minimal sufficient set of symbols via ngx::core::prelude::* and ngx::http::prelude::*
  2. Use enums and bitflags as much as possible.
    E.g. wrapping NGX_CONF_... with bitflags would save a few imports and remove noisy as ngx_uint_t casts.
  3. Reduce boilerplate code. For example,
    #[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
    }
    would remove a couple of imports that are never necessary in the code and reduce amount of copy-paste needed to get started.

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions