Skip to content

Commit

Permalink
chore: apply group_imports = "StdExternalCrate"[1]
Browse files Browse the repository at this point in the history
Unmerge a few excessively complex import statements.

The option itself is unstable, so it is commented in rustfmt.toml.

[1]: https://rust-lang.github.io/rustfmt/?version=master&search=#group_imports
  • Loading branch information
bavshin-f5 committed Oct 25, 2024
1 parent a8231c3 commit 969c870
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 54 deletions.
11 changes: 6 additions & 5 deletions examples/async.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
use std::ffi::{c_char, c_void};
use std::ptr::{addr_of, addr_of_mut};
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use std::time::Instant;

use ngx::core;
use ngx::ffi::{
nginx_version, ngx_array_push, ngx_command_t, ngx_conf_t, ngx_cycle, ngx_event_t, ngx_http_core_module,
Expand All @@ -7,11 +13,6 @@ use ngx::ffi::{
};
use ngx::http::{self, HTTPModule, MergeConfigError};
use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string};
use std::ffi::{c_char, c_void};
use std::ptr::{addr_of, addr_of_mut};
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
use std::time::Instant;
use tokio::runtime::Runtime;

struct Module;
Expand Down
5 changes: 3 additions & 2 deletions examples/awssig.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::ffi::{c_char, c_void};
use std::ptr::addr_of;

use http::HeaderMap;
use ngx::core;
use ngx::ffi::{
Expand All @@ -8,8 +11,6 @@ use ngx::ffi::{
};
use ngx::http::*;
use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string};
use std::ffi::{c_char, c_void};
use std::ptr::addr_of;

struct Module;

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

use ngx::core;
use ngx::ffi::{
nginx_version, ngx_array_push, ngx_command_t, ngx_conf_t, ngx_http_core_module, ngx_http_handler_pt,
Expand All @@ -6,8 +9,6 @@ use ngx::ffi::{
};
use ngx::http::{self, HTTPModule, MergeConfigError};
use ngx::{http_request_handler, ngx_log_debug_http, ngx_null_command, ngx_string};
use std::ffi::{c_char, c_void};
use std::ptr::addr_of;

struct Module;

Expand Down
5 changes: 3 additions & 2 deletions examples/httporigdst.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::ffi::{c_char, c_int, c_void};
use std::ptr::addr_of;

use ngx::core;
use ngx::ffi::{
in_port_t, nginx_version, ngx_conf_t, ngx_connection_local_sockaddr, ngx_http_add_variable, ngx_http_module_t,
Expand All @@ -6,8 +9,6 @@ use ngx::ffi::{
};
use ngx::http::{self, HTTPModule};
use ngx::{http_variable_get, ngx_http_null_variable, ngx_log_debug_http, ngx_null_string, ngx_string};
use std::ffi::{c_char, c_int, c_void};
use std::ptr::addr_of;

const IPV4_STRLEN: usize = INET_ADDRSTRLEN as usize;

Expand Down
40 changes: 18 additions & 22 deletions examples/upstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,26 @@
* The NGINX authors are grateful to @gabihodoroaga for their contributions
* to the community at large.
*/
use ngx::{
core::{Pool, Status},
ffi::{
nginx_version, ngx_atoi, ngx_command_t, ngx_conf_log_error, 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_UPS_CONF,
NGX_LOG_EMERG, NGX_RS_HTTP_SRV_CONF_OFFSET, NGX_RS_MODULE_SIGNATURE,
},
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,
},
http_upstream_init_peer_pt,
log::DebugMask,
ngx_log_debug_http, ngx_log_debug_mask, ngx_null_command, ngx_string,
use std::ffi::{c_char, c_void};
use std::mem;
use std::ptr::addr_of;
use std::slice;

use ngx::core::{Pool, Status};
use ngx::ffi::{
nginx_version, ngx_atoi, ngx_command_t, ngx_conf_log_error, 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_UPS_CONF, NGX_LOG_EMERG, NGX_RS_HTTP_SRV_CONF_OFFSET,
NGX_RS_MODULE_SIGNATURE,
};
use std::{
ffi::{c_char, c_void},
mem,
ptr::addr_of,
slice,
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,
};
use ngx::log::DebugMask;
use ngx::{http_upstream_init_peer_pt, ngx_log_debug_http, ngx_log_debug_mask, ngx_null_command, ngx_string};

#[derive(Clone, Copy, Debug)]
#[repr(C)]
Expand Down
1 change: 1 addition & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# group_imports = "StdExternalCrate" # unstable
max_width = 120
4 changes: 2 additions & 2 deletions src/core/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ffi::*;

use std::slice;

use crate::ffi::*;

/// The `Buffer` trait provides methods for working with an nginx buffer (`ngx_buf_t`).
pub trait Buffer {
/// Returns a raw pointer to the underlying `ngx_buf_t` of the buffer.
Expand Down
6 changes: 3 additions & 3 deletions src/core/pool.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::core::buffer::{Buffer, MemoryBuffer, TemporaryBuffer};
use crate::ffi::*;

use std::ffi::c_void;
use std::{mem, ptr};

use crate::core::buffer::{Buffer, MemoryBuffer, TemporaryBuffer};
use crate::ffi::*;

/// Wrapper struct for an `ngx_pool_t` pointer, providing methods for working with memory pools.
pub struct Pool(*mut ngx_pool_t);

Expand Down
3 changes: 2 additions & 1 deletion src/core/status.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::ffi::*;
use std::fmt;

use crate::ffi::*;

/// Status
///
/// Rust native wrapper for NGINX status codes.
Expand Down
4 changes: 2 additions & 2 deletions src/core/string.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::ffi::*;

use std::borrow::Cow;
use std::slice;
use std::str::{self, Utf8Error};

use crate::ffi::*;

/// Static string initializer for [`ngx_str_t`].
///
/// The resulting byte string is always nul-terminated (just like a C string).
Expand Down
4 changes: 2 additions & 2 deletions src/http/conf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::ffi::*;

use std::ffi::c_void;

use crate::ffi::*;

/// # Safety
///
/// The caller has provided a valid `ngx_conf_t` that points to valid memory and is non-null.
Expand Down
6 changes: 3 additions & 3 deletions src/http/module.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::ffi::{c_char, c_void};
use std::ptr;

use crate::core::NGX_CONF_ERROR;
use crate::core::*;
use crate::ffi::*;

use std::ffi::{c_char, c_void};
use std::ptr;

/// MergeConfigError - configuration cannot be merged with levels above.
#[derive(Debug)]
pub enum MergeConfigError {
Expand Down
10 changes: 5 additions & 5 deletions src/http/request.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::error::Error;
use std::ffi::c_void;
use std::fmt;
use std::str::FromStr;

use crate::core::*;
use crate::ffi::*;
use crate::http::status::*;
use crate::ngx_null_string;
use std::ffi::c_void;
use std::fmt;

use std::error::Error;
use std::str::FromStr;

/// Define a static request handler.
///
Expand Down
5 changes: 3 additions & 2 deletions src/http/status.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::core::Status;
use crate::ffi::*;
use std::error::Error;
use std::fmt;

use crate::core::Status;
use crate::ffi::*;

/// Represents an HTTP status code.
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct HTTPStatus(pub ngx_uint_t);
Expand Down
3 changes: 2 additions & 1 deletion tests/log_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ impl Nginx {

#[cfg(test)]
mod tests {
use super::*;
use std::env;

use super::*;

const TEST_NGINX_CONFIG: &str = "tests/nginx.conf";

#[test]
Expand Down

0 comments on commit 969c870

Please sign in to comment.