From 5fd9d7ce90864899e494d5f536ea28b904ef845b Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 30 Dec 2024 18:40:31 +0500 Subject: [PATCH] Enable rustls/std feature (#494) --- .github/workflows/checks.yml | 6 +++--- ntex-bytes/src/bytes.rs | 6 +++--- ntex-bytes/src/hex.rs | 4 ++-- ntex-http/src/map.rs | 6 +++--- ntex-http/src/serde.rs | 2 +- ntex-http/src/value.rs | 8 ++++---- ntex-io/src/buf.rs | 4 ++-- ntex-io/src/tasks.rs | 2 +- ntex-router/src/lib.rs | 8 ++++---- ntex-tls/CHANGES.md | 4 ++++ ntex-tls/Cargo.toml | 6 +++--- ntex-tls/src/rustls/mod.rs | 4 ++-- ntex/src/http/error.rs | 2 +- ntex/src/http/helpers.rs | 2 +- ntex/src/web/middleware/logger.rs | 2 +- 15 files changed, 35 insertions(+), 31 deletions(-) diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index bcda73b1..5c91b01d 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: check: - name: Check for build failures + name: Check runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -12,7 +12,7 @@ jobs: with: toolchain: stable - run: - cargo check --all --no-default-features --features="ntex/compio,ntex/cookie,ntex/url,ntex/compress,ntex/openssl,ntex/rustls,ntex/ws,ntex/brotli" + cargo check --tests --all --no-default-features --features="ntex/compio,ntex/cookie,ntex/url,ntex/compress,ntex/openssl,ntex/rustls,ntex/ws,ntex/brotli" clippy: name: Clippy @@ -24,7 +24,7 @@ jobs: toolchain: stable components: clippy - run: - cargo test --all --no-default-features --features="ntex/compio,ntex/cookie,ntex/url,ntex/compress,ntex/openssl,ntex/rustls,ntex/ws,ntex/brotli" + cargo clippy --tests --all --no-default-features --features="ntex/compio,ntex/cookie,ntex/url,ntex/compress,ntex/openssl,ntex/rustls,ntex/ws,ntex/brotli" fmt: name: Rustfmt diff --git a/ntex-bytes/src/bytes.rs b/ntex-bytes/src/bytes.rs index 77267307..b7eb8eea 100644 --- a/ntex-bytes/src/bytes.rs +++ b/ntex-bytes/src/bytes.rs @@ -3779,7 +3779,7 @@ impl PartialEq for [u8; N] { } } -impl<'a, const N: usize> PartialEq for &'a [u8; N] { +impl PartialEq for &[u8; N] { fn eq(&self, other: &BytesMut) -> bool { *other == *self } @@ -3878,7 +3878,7 @@ impl PartialEq for [u8; N] { } } -impl<'a, const N: usize> PartialEq for &'a [u8; N] { +impl PartialEq for &[u8; N] { fn eq(&self, other: &Bytes) -> bool { *other == *self } @@ -4076,7 +4076,7 @@ impl PartialEq for [u8; N] { } } -impl<'a, const N: usize> PartialEq for &'a [u8; N] { +impl PartialEq for &[u8; N] { fn eq(&self, other: &BytesVec) -> bool { *other == *self } diff --git a/ntex-bytes/src/hex.rs b/ntex-bytes/src/hex.rs index 46ad1e1f..109b2462 100644 --- a/ntex-bytes/src/hex.rs +++ b/ntex-bytes/src/hex.rs @@ -3,7 +3,7 @@ use std::fmt::{Formatter, LowerHex, Result, UpperHex}; struct BytesRef<'a>(&'a [u8]); -impl<'a> LowerHex for BytesRef<'a> { +impl LowerHex for BytesRef<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> Result { for b in self.0 { write!(f, "{b:02x}")?; @@ -12,7 +12,7 @@ impl<'a> LowerHex for BytesRef<'a> { } } -impl<'a> UpperHex for BytesRef<'a> { +impl UpperHex for BytesRef<'_> { fn fmt(&self, f: &mut Formatter<'_>) -> Result { for b in self.0 { write!(f, "{b:02X}")?; diff --git a/ntex-http/src/map.rs b/ntex-http/src/map.rs index 53124b55..16e0fcd8 100644 --- a/ntex-http/src/map.rs +++ b/ntex-http/src/map.rs @@ -354,13 +354,13 @@ impl AsName for HeaderName { } } -impl<'a> AsName for &'a HeaderName { +impl AsName for &HeaderName { fn as_name(&self) -> Either<&HeaderName, &str> { Either::Left(self) } } -impl<'a> AsName for &'a str { +impl AsName for &str { fn as_name(&self) -> Either<&HeaderName, &str> { Either::Right(self) } @@ -372,7 +372,7 @@ impl AsName for String { } } -impl<'a> AsName for &'a String { +impl AsName for &String { fn as_name(&self) -> Either<&HeaderName, &str> { Either::Right(self.as_str()) } diff --git a/ntex-http/src/serde.rs b/ntex-http/src/serde.rs index 88ae23e0..b282b3b7 100644 --- a/ntex-http/src/serde.rs +++ b/ntex-http/src/serde.rs @@ -158,7 +158,7 @@ impl<'de> Deserialize<'de> for HeaderValue { struct HeaderValueVisitor; -impl<'de> Visitor<'de> for HeaderValueVisitor { +impl Visitor<'_> for HeaderValueVisitor { type Value = HeaderValue; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/ntex-http/src/value.rs b/ntex-http/src/value.rs index 27b197c6..e2db9036 100644 --- a/ntex-http/src/value.rs +++ b/ntex-http/src/value.rs @@ -641,14 +641,14 @@ impl PartialOrd for String { } } -impl<'a> PartialEq for &'a HeaderValue { +impl PartialEq for &HeaderValue { #[inline] fn eq(&self, other: &HeaderValue) -> bool { **self == *other } } -impl<'a> PartialOrd for &'a HeaderValue { +impl PartialOrd for &HeaderValue { #[inline] fn partial_cmp(&self, other: &HeaderValue) -> Option { (**self).partial_cmp(other) @@ -675,14 +675,14 @@ where } } -impl<'a> PartialEq for &'a str { +impl PartialEq for &str { #[inline] fn eq(&self, other: &HeaderValue) -> bool { *other == *self } } -impl<'a> PartialOrd for &'a str { +impl PartialOrd for &str { #[inline] fn partial_cmp(&self, other: &HeaderValue) -> Option { self.as_bytes().partial_cmp(other.as_bytes()) diff --git a/ntex-io/src/buf.rs b/ntex-io/src/buf.rs index 7d4624f0..82032f8c 100644 --- a/ntex-io/src/buf.rs +++ b/ntex-io/src/buf.rs @@ -300,7 +300,7 @@ pub struct ReadBuf<'a> { pub(crate) need_write: Cell, } -impl<'a> ReadBuf<'a> { +impl ReadBuf<'_> { #[inline] /// Get io tag pub fn tag(&self) -> &'static str { @@ -444,7 +444,7 @@ pub struct WriteBuf<'a> { pub(crate) need_write: Cell, } -impl<'a> WriteBuf<'a> { +impl WriteBuf<'_> { #[inline] /// Get io tag pub fn tag(&self) -> &'static str { diff --git a/ntex-io/src/tasks.rs b/ntex-io/src/tasks.rs index 497e1f6c..4994595c 100644 --- a/ntex-io/src/tasks.rs +++ b/ntex-io/src/tasks.rs @@ -87,7 +87,7 @@ impl ReadContext { // handle incoming data let total2 = buf.len(); - let nbytes = if total2 > total { total2 - total } else { 0 }; + let nbytes = total2.saturating_sub(total); let total = total2; if let Some(mut first_buf) = inner.buffer.get_read_source() { diff --git a/ntex-router/src/lib.rs b/ntex-router/src/lib.rs index c0951890..6d205faa 100644 --- a/ntex-router/src/lib.rs +++ b/ntex-router/src/lib.rs @@ -42,7 +42,7 @@ impl ResourcePath for String { } } -impl<'a> ResourcePath for &'a str { +impl ResourcePath for &str { fn path(&self) -> &str { self } @@ -54,7 +54,7 @@ impl ResourcePath for ntex_bytes::ByteString { } } -impl<'a, T: ResourcePath> ResourcePath for &'a T { +impl ResourcePath for &T { fn path(&self) -> &str { (*self).path() } @@ -71,13 +71,13 @@ impl IntoPattern for String { } } -impl<'a> IntoPattern for &'a String { +impl IntoPattern for &String { fn patterns(&self) -> Vec { vec![self.as_str().to_string()] } } -impl<'a> IntoPattern for &'a str { +impl IntoPattern for &str { fn patterns(&self) -> Vec { vec![(*self).to_string()] } diff --git a/ntex-tls/CHANGES.md b/ntex-tls/CHANGES.md index 8e417bc4..94d5b547 100644 --- a/ntex-tls/CHANGES.md +++ b/ntex-tls/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [2.4.0] - 2024-12-30 + +* Enable rustls/std feature + ## [2.3.0] - 2024-11-04 * Use updated Service trait diff --git a/ntex-tls/Cargo.toml b/ntex-tls/Cargo.toml index 4a731964..701128c8 100644 --- a/ntex-tls/Cargo.toml +++ b/ntex-tls/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ntex-tls" -version = "2.3.0" +version = "2.4.0" authors = ["ntex contributors "] description = "An implementation of SSL streams for ntex backed by OpenSSL" keywords = ["network", "framework", "async", "futures"] @@ -22,14 +22,14 @@ default = [] openssl = ["tls_openssl"] # rustls support -rustls = ["tls_rust"] +rustls = ["tls_rust", "tls_rust/std"] rustls-ring = ["tls_rust", "tls_rust/ring", "tls_rust/std"] [dependencies] ntex-bytes = "0.1" ntex-io = "2.3" ntex-util = "2.5" -ntex-service = "3.3" +ntex-service = "3.4" ntex-net = "2" log = "0.4" diff --git a/ntex-tls/src/rustls/mod.rs b/ntex-tls/src/rustls/mod.rs index 1d1ef685..70f48661 100644 --- a/ntex-tls/src/rustls/mod.rs +++ b/ntex-tls/src/rustls/mod.rs @@ -24,7 +24,7 @@ pub struct PeerCertChain<'a>(pub Vec>); pub(crate) struct Wrapper<'a, 'b>(&'a WriteBuf<'b>); -impl<'a, 'b> io::Read for Wrapper<'a, 'b> { +impl io::Read for Wrapper<'_, '_> { fn read(&mut self, dst: &mut [u8]) -> io::Result { self.0.with_read_buf(|buf| { buf.with_src(|buf| { @@ -41,7 +41,7 @@ impl<'a, 'b> io::Read for Wrapper<'a, 'b> { } } -impl<'a, 'b> io::Write for Wrapper<'a, 'b> { +impl io::Write for Wrapper<'_, '_> { fn write(&mut self, src: &[u8]) -> io::Result { self.0.with_dst(|buf| buf.extend_from_slice(src)); Ok(src.len()) diff --git a/ntex/src/http/error.rs b/ntex/src/http/error.rs index f1eba14a..8703a258 100644 --- a/ntex/src/http/error.rs +++ b/ntex/src/http/error.rs @@ -29,7 +29,7 @@ pub trait ResponseError: fmt::Display + fmt::Debug { } } -impl<'a, T: ResponseError> ResponseError for &'a T { +impl ResponseError for &T { fn error_response(&self) -> Response { (*self).error_response() } diff --git a/ntex/src/http/helpers.rs b/ntex/src/http/helpers.rs index 588aafce..ed3a26b5 100644 --- a/ntex/src/http/helpers.rs +++ b/ntex/src/http/helpers.rs @@ -6,7 +6,7 @@ use crate::util::BytesMut; pub(crate) struct Writer<'a>(pub(crate) &'a mut BytesMut); -impl<'a> io::Write for Writer<'a> { +impl io::Write for Writer<'_> { fn write(&mut self, buf: &[u8]) -> io::Result { self.0.extend_from_slice(buf); Ok(buf.len()) diff --git a/ntex/src/web/middleware/logger.rs b/ntex/src/web/middleware/logger.rs index cd99d5bb..26f4f4a6 100644 --- a/ntex/src/web/middleware/logger.rs +++ b/ntex/src/web/middleware/logger.rs @@ -400,7 +400,7 @@ pub(crate) struct FormatDisplay<'a>( &'a dyn Fn(&mut fmt::Formatter<'_>) -> Result<(), fmt::Error>, ); -impl<'a> fmt::Display for FormatDisplay<'a> { +impl fmt::Display for FormatDisplay<'_> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { (self.0)(fmt) }