Skip to content

Commit a1e55cd

Browse files
Matthew Yacobucciivanitskiy
authored andcommitted
chore: clippy lint -Dwarnings
1 parent 57c68ff commit a1e55cd

File tree

7 files changed

+71
-17
lines changed

7 files changed

+71
-17
lines changed

nginx-sys/src/lib.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
//! ```rust,no_run
2525
//! use nginx_sys::nginx_version;
2626
//!
27-
//! fn main() {
28-
//! let version = unsafe { nginx_version() };
29-
//! println!("Nginx version: {}", version);
30-
//! }
27+
//! let version = unsafe { nginx_version() };
28+
//! println!("Nginx version: {}", version);
3129
//! ```
3230
//!
3331
#![warn(missing_docs)]
@@ -45,7 +43,7 @@ mod bindings {
4543
#![allow(dead_code)]
4644
#![allow(clippy::all)]
4745
#![allow(improper_ctypes)]
48-
#[allow(rustdoc::broken_intra_doc_links)]
46+
#![allow(rustdoc::broken_intra_doc_links)]
4947
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
5048
}
5149
#[doc(no_inline)]
@@ -89,19 +87,11 @@ impl ngx_str_t {
8987
/// A string slice (`&str`) representing the nginx string.
9088
pub fn to_str(&self) -> &str {
9189
unsafe {
92-
let slice = slice::from_raw_parts(self.data, self.len as usize);
90+
let slice = slice::from_raw_parts(self.data, self.len);
9391
return std::str::from_utf8(slice).unwrap();
9492
}
9593
}
9694

97-
/// Convert the nginx string to a `String` by copying its contents.
98-
///
99-
/// # Returns
100-
/// A new `String` containing the contents of the nginx string.
101-
pub fn to_string(&self) -> String {
102-
return String::from(self.to_str());
103-
}
104-
10595
/// Create an `ngx_str_t` instance from a `String`.
10696
///
10797
/// # Arguments
@@ -140,7 +130,7 @@ impl From<ngx_str_t> for &[u8] {
140130
if s.len == 0 || s.data.is_null() {
141131
return Default::default();
142132
}
143-
unsafe { slice::from_raw_parts(s.data, s.len as usize) }
133+
unsafe { slice::from_raw_parts(s.data, s.len) }
144134
}
145135
}
146136

src/core/status.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
use crate::ffi::*;
22
use std::fmt;
33

4+
/// Status
5+
///
6+
/// Rust native wrapper for NGINX status codes.
47
#[derive(Ord, PartialOrd, Eq, PartialEq)]
58
pub struct Status(pub ngx_int_t);
69

710
impl Status {
11+
/// Is this Status equivalent to NGX_OK?
812
pub fn is_ok(&self) -> bool {
913
self == &Status::NGX_OK
1014
}
@@ -40,13 +44,23 @@ macro_rules! ngx_codes {
4044
}
4145

4246
ngx_codes! {
47+
/// NGX_OK - Operation succeeded.
4348
(NGX_OK);
49+
/// NGX_ERROR - Operation failed.
4450
(NGX_ERROR);
51+
/// NGX_AGAIN - Operation incomplete; call the function again.
4552
(NGX_AGAIN);
53+
/// NGX_BUSY - Resource is not available.
4654
(NGX_BUSY);
55+
/// NGX_DONE - Operation complete or continued elsewhere. Also used as an alternative success code.
4756
(NGX_DONE);
57+
/// NGX_DECLINED - Operation rejected, for example, because it is disabled in the configuration.
58+
/// This is never an error.
4859
(NGX_DECLINED);
60+
/// NGX_ABORT - Function was aborted. Also used as an alternative error code.
4961
(NGX_ABORT);
5062
}
63+
64+
/// NGX_CONF_ERROR - An error occurred while parsing and validating configuration.
5165
pub const NGX_CONF_ERROR: *const () = -1isize as *const ();
5266
// pub const CONF_OK: Status = Status(NGX_CONF_OK as ngx_int_t);

src/http/module.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::ffi::*;
55
use core::ptr;
66
use std::os::raw::{c_char, c_void};
77

8+
/// MergeConfigError - configuration cannot be merged with levels above.
89
#[derive(Debug)]
910
pub enum MergeConfigError {
1011
/// No value provided for configuration argument
@@ -21,7 +22,15 @@ impl std::fmt::Display for MergeConfigError {
2122
}
2223
}
2324

25+
/// The `Merge` trait provides a method for merging configuration down through each level.
26+
///
27+
/// A module configuration should implement this trait for setting its configuration throughout
28+
/// each level.
2429
pub trait Merge {
30+
/// Module merge function.
31+
///
32+
/// # Returns
33+
/// Result, Ok on success or MergeConfigError on failure.
2534
fn merge(&mut self, prev: &Self) -> Result<(), MergeConfigError>;
2635
}
2736

@@ -31,9 +40,18 @@ impl Merge for () {
3140
}
3241
}
3342

43+
/// The `HTTPModule` trait provides the NGINX configuration stage interface.
44+
///
45+
/// These functions allocate structures, initialize them, and merge through the configuration
46+
/// layers.
47+
///
48+
/// See https://nginx.org/en/docs/dev/development_guide.html#adding_new_modules for details.
3449
pub trait HTTPModule {
50+
/// Configuration in the `http` block.
3551
type MainConf: Merge + Default;
52+
/// Configuration in a `server` block within the `http` block.
3653
type SrvConf: Merge + Default;
54+
/// Configuration in a `location` block within the `http` block.
3755
type LocConf: Merge + Default;
3856

3957
/// # Safety

src/http/request.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ impl Request {
149149
Some(co)
150150
}
151151

152+
/// Sets the value as the module's context.
153+
///
154+
/// See https://nginx.org/en/docs/dev/development_guide.html#http_request
152155
pub fn set_module_ctx(&self, value: *mut c_void, module: &ngx_module_t) {
153156
unsafe {
154157
*self.0.ctx.add(module.ctx_index) = value;
@@ -191,11 +194,17 @@ impl Request {
191194
self.0.headers_out.status = status.into();
192195
}
193196

197+
/// Add header to the `headers_in` object.
198+
///
199+
/// See https://nginx.org/en/docs/dev/development_guide.html#http_request
194200
pub fn add_header_in(&mut self, key: &str, value: &str) -> Option<()> {
195201
let table: *mut ngx_table_elt_t = unsafe { ngx_list_push(&mut self.0.headers_in.headers) as _ };
196202
add_to_ngx_table(table, self.0.pool, key, value)
197203
}
198204

205+
/// Add header to the `headers_out` object.
206+
///
207+
/// See https://nginx.org/en/docs/dev/development_guide.html#http_request
199208
pub fn add_header_out(&mut self, key: &str, value: &str) -> Option<()> {
200209
let table: *mut ngx_table_elt_t = unsafe { ngx_list_push(&mut self.0.headers_out.headers) as _ };
201210
add_to_ngx_table(table, self.0.pool, key, value)
@@ -340,6 +349,9 @@ impl fmt::Debug for Request {
340349
}
341350
}
342351

352+
/// Iterator for `ngx_list_t` types.
353+
///
354+
/// Implementes the std::iter::Iterator trait.
343355
pub struct NgxListIterator {
344356
done: bool,
345357
part: *const ngx_list_part_t,
@@ -459,6 +471,7 @@ impl Method {
459471
/// CONNECT
460472
pub const CONNECT: Method = Method(MethodInner::Connect);
461473

474+
/// Convert a Method to a &str.
462475
#[inline]
463476
pub fn as_str(&self) -> &str {
464477
match self.0 {

src/http/status.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ impl fmt::Debug for HTTPStatus {
4949
}
5050

5151
impl HTTPStatus {
52+
/// Convets a u16 to a status code.
5253
#[inline]
5354
pub fn from_u16(src: u16) -> Result<HTTPStatus, InvalidHTTPStatusCode> {
5455
if !(100..600).contains(&src) {
@@ -58,7 +59,7 @@ impl HTTPStatus {
5859
Ok(HTTPStatus(src.into()))
5960
}
6061

61-
/// Converts a &[u8] to a status code
62+
/// Converts a &[u8] to a status code.
6263
pub fn from_bytes(src: &[u8]) -> Result<HTTPStatus, InvalidHTTPStatusCode> {
6364
if src.len() != 3 {
6465
return Err(InvalidHTTPStatusCode::new());

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,27 @@
3333
//! ```
3434
3535
#![warn(missing_docs)]
36+
/// The core module.
37+
///
38+
/// This module provides fundamental utilities needed to interface with many NGINX primitives.
39+
/// String conversions, the pool (memory interface) object, and buffer APIs are covered here. These
40+
/// utilities will generally align with the NGINX 'core' files and APIs.
3641
pub mod core;
42+
43+
/// The ffi module.
44+
///
45+
/// This module provides scoped FFI bindings for NGINX symbols.
3746
pub mod ffi;
47+
48+
/// The http module.
49+
///
50+
/// This modules provides wrappers and utilities to NGINX http APIs, such as requests,
51+
/// configuration access, and statuses.
3852
pub mod http;
53+
54+
/// The log module.
55+
///
56+
/// This module provides an interface into the NGINX logger framework.
3957
pub mod log;
4058

4159
/// Define modules exported by this library.

tests/log_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl Nginx {
6565
// make sure we stop existing nginx and start new master process
6666
// intentinally ignore failure in stop
6767
pub fn restart(&mut self) -> Result<Output> {
68-
self.stop();
68+
let _ = self.stop();
6969
self.start()
7070
}
7171

0 commit comments

Comments
 (0)