Skip to content

Commit 445cb31

Browse files
committed
fix: replce std to core, and cfg out, except log
1 parent d06dae4 commit 445cb31

File tree

13 files changed

+50
-43
lines changed

13 files changed

+50
-43
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ rust-version.workspace = true
2828
nginx-sys = { path = "nginx-sys", version = "0.5.0"}
2929

3030
[features]
31-
default = ["vendored"]
31+
default = ["vendored","std"]
32+
# use std memory allocation
33+
std = []
3234
# Build our own copy of the NGINX by default.
3335
# This could be disabled with `--no-default-features` to minimize the dependency tree
3436
# when building against an existing copy of the NGINX with the NGX_OBJS variable.

nginx-sys/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ ureq = { version = "2.9.6", features = ["tls"], optional = true }
2727
which = { version = "6.0.0", optional = true }
2828

2929
[features]
30+
default = ["std"]
31+
std = []
3032
vendored = ["dep:which", "dep:duct", "dep:ureq", "dep:flate2", "dep:tar"]

nginx-sys/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![doc = include_str!("../README.md")]
22
#![warn(missing_docs)]
33

4-
use std::fmt;
5-
use std::ptr::copy_nonoverlapping;
6-
use std::slice;
4+
use core::fmt;
5+
use core::ptr::copy_nonoverlapping;
6+
use core::slice;
77

88
#[doc(hidden)]
99
mod bindings {
@@ -104,7 +104,7 @@ impl ngx_str_t {
104104
/// # Returns
105105
/// A string slice (`&str`) representing the nginx string.
106106
pub fn to_str(&self) -> &str {
107-
std::str::from_utf8(self.as_bytes()).unwrap()
107+
core::str::from_utf8(self.as_bytes()).unwrap()
108108
}
109109

110110
/// Create an `ngx_str_t` instance from a byte slice.
@@ -168,6 +168,7 @@ impl From<ngx_str_t> for &[u8] {
168168
}
169169
}
170170

171+
#[cfg(feature = "std")]
171172
impl TryFrom<ngx_str_t> for String {
172173
type Error = std::string::FromUtf8Error;
173174

@@ -184,10 +185,10 @@ impl fmt::Display for ngx_str_t {
184185
}
185186

186187
impl TryFrom<ngx_str_t> for &str {
187-
type Error = std::str::Utf8Error;
188+
type Error = core::str::Utf8Error;
188189

189190
fn try_from(s: ngx_str_t) -> Result<Self, Self::Error> {
190-
std::str::from_utf8(s.into())
191+
core::str::from_utf8(s.into())
191192
}
192193
}
193194

src/core/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::slice;
1+
use core::slice;
22

33
use crate::ffi::*;
44

src/core/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ macro_rules! ngx_null_command {
2222
set: None,
2323
conf: 0,
2424
offset: 0,
25-
post: ::std::ptr::null_mut(),
25+
post: ::core::ptr::null_mut(),
2626
}
2727
};
2828
}

src/core/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::ffi::c_void;
2-
use std::{mem, ptr};
1+
use core::ffi::c_void;
2+
use core::{mem, ptr};
33

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

src/core/status.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fmt;
1+
use core::fmt;
22

33
use crate::ffi::*;
44

src/core/string.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use std::borrow::Cow;
2-
use std::slice;
3-
use std::str::{self, Utf8Error};
1+
use core::slice;
2+
use core::str::{self, Utf8Error};
43

54
use crate::ffi::*;
65

@@ -27,7 +26,7 @@ macro_rules! ngx_null_string {
2726
() => {
2827
$crate::ffi::ngx_str_t {
2928
len: 0,
30-
data: ::std::ptr::null_mut(),
29+
data: ::core::ptr::null_mut(),
3130
}
3231
};
3332
}
@@ -64,7 +63,8 @@ impl NgxStr {
6463
/// Converts an [`NgxStr`] into a [`Cow<str>`], replacing invalid UTF-8 sequences.
6564
///
6665
/// See [`String::from_utf8_lossy`].
67-
pub fn to_string_lossy(&self) -> Cow<str> {
66+
#[cfg(feature = "std")]
67+
pub fn to_string_lossy(&self) -> std::borrow::Cow<str> {
6868
String::from_utf8_lossy(self.as_bytes())
6969
}
7070

src/http/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::ffi::c_void;
1+
use core::ffi::c_void;
22

33
use crate::ffi::*;
44

src/http/module.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::ffi::{c_char, c_void};
2-
use std::ptr;
1+
use core::ffi::{c_char, c_void};
2+
use core::ptr;
33

44
use crate::core::NGX_CONF_ERROR;
55
use crate::core::*;
@@ -12,10 +12,10 @@ pub enum MergeConfigError {
1212
NoValue,
1313
}
1414

15-
impl std::error::Error for MergeConfigError {}
15+
impl core::error::Error for MergeConfigError {}
1616

17-
impl std::fmt::Display for MergeConfigError {
18-
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
17+
impl core::fmt::Display for MergeConfigError {
18+
fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
1919
match self {
2020
MergeConfigError::NoValue => "no value".fmt(fmt),
2121
}

0 commit comments

Comments
 (0)