Skip to content

Commit b8e1971

Browse files
authored
Better clippy configuration (#81)
1 parent 6a979a6 commit b8e1971

36 files changed

+471
-457
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changes
22

3+
## [3.6.2] - 2026-02-11
4+
5+
* Better clippy configuration
6+
37
## [3.6.1] - 2026-02-02
48

59
* Make control module public

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ntex-h2"
3-
version = "3.6.1"
3+
version = "3.6.2"
44
license = "MIT OR Apache-2.0"
55
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
66
description = "An HTTP/2 client and server"
@@ -23,13 +23,13 @@ unstable = []
2323
features = []
2424

2525
[dependencies]
26-
ntex-bytes = "1.4"
26+
ntex-bytes = "1.5"
2727
ntex-codec = "1.1"
2828
ntex-dispatcher = "3"
2929
ntex-http = "1"
3030
ntex-io = "3.7"
3131
ntex-net = "3"
32-
ntex-service = "4"
32+
ntex-service = "4.4"
3333
ntex-util = "3"
3434

3535
bitflags = "2"
@@ -50,7 +50,7 @@ walkdir = "2.3.2"
5050
serde = "1"
5151
serde_json = "1"
5252

53-
ntex = { version = "3.0.0-pre.15", features = ["openssl"] }
53+
ntex = { version = "3.2", features = ["openssl"] }
5454
ntex-tls = { version = "3", features = ["openssl"] }
5555
openssl = "0.10"
5656

src/client/connector.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{client::ClientError, config::ServiceConfig};
1414
#[derive(Debug)]
1515
/// Http2 client connector
1616
pub struct Connector<A: Address, T> {
17-
connector: T,
17+
svc: T,
1818
scheme: Scheme,
1919
pool: pool::Pool<()>,
2020

@@ -28,12 +28,12 @@ where
2828
IoBoxed: From<T::Response>,
2929
{
3030
/// Create new http2 connector
31-
pub fn new<F>(connector: F) -> Connector<A, T>
31+
pub fn new<F>(svc: F) -> Connector<A, T>
3232
where
3333
F: IntoServiceFactory<T, Connect<A>, SharedCfg>,
3434
{
3535
Connector {
36-
connector: connector.into_factory(),
36+
svc: svc.into_factory(),
3737
scheme: Scheme::HTTP,
3838
pool: pool::new(),
3939
_t: PhantomData,
@@ -63,14 +63,14 @@ where
6363
}
6464

6565
/// Use custom connector
66-
pub fn connector<U, F>(&self, connector: F) -> Connector<A, U>
66+
pub fn connector<U, F>(&self, svc: F) -> Connector<A, U>
6767
where
6868
F: IntoServiceFactory<U, Connect<A>, SharedCfg>,
6969
U: ServiceFactory<Connect<A>, SharedCfg, Error = ConnectError>,
7070
IoBoxed: From<U::Response>,
7171
{
7272
Connector {
73-
connector: connector.into_factory(),
73+
svc: svc.into_factory(),
7474
scheme: self.scheme.clone(),
7575
pool: self.pool.clone(),
7676
_t: PhantomData,
@@ -90,7 +90,7 @@ where
9090
type Service = ConnectorService<A, T::Service>;
9191

9292
async fn create(&self, cfg: SharedCfg) -> Result<Self::Service, Self::InitError> {
93-
let svc = self.connector.create(cfg).await?;
93+
let svc = self.svc.create(cfg).await?;
9494
Ok(ConnectorService {
9595
svc,
9696
scheme: self.scheme.clone(),
@@ -127,7 +127,7 @@ where
127127
Ok::<_, ClientError>(SimpleClient::with_params(
128128
ctx.call(&self.svc, Connect::new(req)).await?.into(),
129129
self.config,
130-
self.scheme.clone(),
130+
&self.scheme,
131131
authority,
132132
false,
133133
InflightStorage::default(),
@@ -137,7 +137,7 @@ where
137137

138138
timeout_checked(self.config.handshake_timeout, fut)
139139
.await
140-
.map_err(|_| ClientError::HandshakeTimeout)
140+
.map_err(|()| ClientError::HandshakeTimeout)
141141
.and_then(|item| item)
142142
}
143143

src/client/pool.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ impl Client {
7777

7878
if let Some(client) = client {
7979
return Ok(client);
80-
} else {
81-
self.connect(num).await?;
8280
}
81+
self.connect(num).await?;
8382
}
8483
}
8584

@@ -120,7 +119,7 @@ impl Client {
120119
} else if connections[idx].is_disconnecting() {
121120
let con = connections.remove(idx);
122121
let timeout = cfg.disconnect_timeout;
123-
let _ = ntex_util::spawn(async move {
122+
ntex_util::spawn(async move {
124123
let _ = con.disconnect().disconnect_timeout(timeout).await;
125124
});
126125
} else {
@@ -164,7 +163,7 @@ impl Client {
164163
let inner = self.inner.clone();
165164
let waiters = self.waiters.clone();
166165

167-
let _ = ntex_util::spawn(async move {
166+
ntex_util::spawn(async move {
168167
let res = match timeout_checked(inner.config.conn_timeout, (*inner.connector)()).await {
169168
Ok(Ok(io)) => {
170169
// callbacks for end of stream
@@ -176,7 +175,7 @@ impl Client {
176175
let client = SimpleClient::with_params(
177176
io,
178177
inner.cfg,
179-
inner.config.scheme.clone(),
178+
&inner.config.scheme,
180179
inner.config.authority.clone(),
181180
inner.config.skip_unknown_streams,
182181
storage,
@@ -190,7 +189,7 @@ impl Client {
190189
Ok(())
191190
}
192191
Ok(Err(err)) => Err(ClientError::from(err)),
193-
Err(_) => Err(ClientError::HandshakeTimeout),
192+
Err(()) => Err(ClientError::HandshakeTimeout),
194193
};
195194
inner.config.connecting.set(false);
196195
for waiter in waiters.borrow_mut().drain(..) {
@@ -230,19 +229,18 @@ impl Client {
230229
/// Client is ready when it is possible to start new stream
231230
pub async fn ready(&self) {
232231
loop {
233-
if !self.is_ready() {
234-
// add waiter
235-
let (tx, rx) = self.inner.config.pool.channel();
236-
self.waiters.borrow_mut().push_back(tx);
237-
let _ = rx.await;
238-
'inner: while let Some(tx) = self.waiters.borrow_mut().pop_front() {
239-
if tx.send(()).is_ok() {
240-
break 'inner;
241-
}
242-
}
243-
} else {
232+
if self.is_ready() {
244233
break;
245234
}
235+
// add waiter
236+
let (tx, rx) = self.inner.config.pool.channel();
237+
self.waiters.borrow_mut().push_back(tx);
238+
let _ = rx.await;
239+
'inner: while let Some(tx) = self.waiters.borrow_mut().pop_front() {
240+
if tx.send(()).is_ok() {
241+
break 'inner;
242+
}
243+
}
246244
}
247245
}
248246
}
@@ -326,7 +324,7 @@ where
326324
maxconn: 16,
327325
scheme: Scheme::HTTP,
328326
connecting: Cell::new(false),
329-
connections: Default::default(),
327+
connections: RefCell::default(),
330328
total_connections: Cell::new(0),
331329
connect_errors: Cell::new(0),
332330
pool: pool::new(),
@@ -352,23 +350,26 @@ impl<A, T> ClientBuilder<A, T>
352350
where
353351
A: Address + Clone,
354352
{
355-
#[inline]
353+
#[must_use]
356354
/// Set client's connection scheme
357355
pub fn scheme(mut self, scheme: Scheme) -> Self {
358356
self.inner.scheme = scheme;
359357
self
360358
}
361359

360+
#[must_use]
362361
/// Set total number of simultaneous streams per connection.
363362
///
364-
/// If limit is 0, the connector uses "MAX_CONCURRENT_STREAMS" config from connection
365-
/// settings.
363+
/// If limit is 0, the connector uses `MAX_CONCURRENT_STREAMS` config
364+
/// from connection settings.
365+
///
366366
/// The default limit size is 100.
367367
pub fn max_streams(mut self, limit: u32) -> Self {
368368
self.inner.max_streams = limit;
369369
self
370370
}
371371

372+
#[must_use]
372373
/// Do not return error for frames for unknown streams.
373374
///
374375
/// This includes pending resets, data and window update frames.
@@ -377,6 +378,7 @@ where
377378
self
378379
}
379380

381+
#[must_use]
380382
/// Set max lifetime period for connection.
381383
///
382384
/// Connection lifetime is max lifetime of any opened connection
@@ -388,6 +390,7 @@ where
388390
self
389391
}
390392

393+
#[must_use]
391394
/// Sets the minimum concurrent connections.
392395
///
393396
/// By default min connections is set to a 1.
@@ -396,6 +399,7 @@ where
396399
self
397400
}
398401

402+
#[must_use]
399403
/// Sets the maximum concurrent connections.
400404
///
401405
/// By default max connections is set to a 16.
@@ -447,7 +451,7 @@ where
447451
cfg: cfg.get(),
448452
config: self.inner,
449453
}),
450-
waiters: Default::default(),
454+
waiters: Rc::default(),
451455
})
452456
}
453457
}

src/client/simple.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct ClientRef {
2929

3030
impl SimpleClient {
3131
/// Construct new `Client` instance.
32+
#[allow(clippy::needless_pass_by_value)]
3233
pub fn new<T>(io: T, scheme: Scheme, authority: ByteString) -> Self
3334
where
3435
IoBoxed: From<T>,
@@ -38,7 +39,7 @@ impl SimpleClient {
3839
SimpleClient::with_params(
3940
io,
4041
cfg,
41-
scheme,
42+
&scheme,
4243
authority,
4344
false,
4445
InflightStorage::default(),
@@ -49,7 +50,7 @@ impl SimpleClient {
4950
pub(super) fn with_params(
5051
io: IoBoxed,
5152
cfg: Cfg<ServiceConfig>,
52-
scheme: Scheme,
53+
scheme: &Scheme,
5354
authority: ByteString,
5455
skip_unknown_streams: bool,
5556
storage: InflightStorage,
@@ -65,7 +66,7 @@ impl SimpleClient {
6566
skip_unknown_streams,
6667
pool,
6768
);
68-
con.set_secure(scheme == Scheme::HTTPS);
69+
con.set_secure(*scheme == Scheme::HTTPS);
6970

7071
let disp = Dispatcher::new(
7172
con.clone(),
@@ -74,7 +75,7 @@ impl SimpleClient {
7475
);
7576

7677
let fut = IoDispatcher::new(io, con.codec().clone(), disp);
77-
let _ = ntex_util::spawn(async move {
78+
ntex_util::spawn(async move {
7879
let _ = fut.await;
7980
});
8081

@@ -136,13 +137,13 @@ impl SimpleClient {
136137
/// Gracefully close connection
137138
pub fn close(&self) {
138139
log::debug!("Closing client");
139-
self.0.con.disconnect_when_ready()
140+
self.0.con.disconnect_when_ready();
140141
}
141142

142143
#[inline]
143144
/// Close connection
144145
pub fn force_close(&self) {
145-
self.0.con.close()
146+
self.0.con.close();
146147
}
147148

148149
#[inline]
@@ -209,8 +210,7 @@ impl SimpleClient {
209210
impl Drop for SimpleClient {
210211
fn drop(&mut self) {
211212
if Rc::strong_count(&self.0) == 1 {
212-
log::debug!("Last h2 client has been dropped, disconnecting");
213-
self.0.con.disconnect_when_ready()
213+
self.0.con.disconnect_when_ready();
214214
}
215215
}
216216
}
@@ -284,7 +284,7 @@ fn gen_id() -> ByteString {
284284
let mut id = String::with_capacity(16);
285285
for _ in 0..16 {
286286
let idx = rng.generate_range::<usize, _>(..BASE.len());
287-
id.push_str(&BASE[idx..idx + 1]);
287+
id.push_str(&BASE[idx..=idx]);
288288
}
289289
ByteString::from(id)
290290
}

0 commit comments

Comments
 (0)