Skip to content

Commit 916346c

Browse files
Ruben24240xE282B0
authored andcommitted
style(lib): cargo fmt cfg workaround (hyperium#3255)
Modules that were marked in macros to conditionally enable them were ignored by `cargo fmt`. This changes CI to manually check all Rust files instead. Also applies missing style changes that were detected. Signed-off-by: Sven Pfennig <[email protected]>
1 parent d8d548a commit 916346c

File tree

14 files changed

+63
-69
lines changed

14 files changed

+63
-69
lines changed

.github/workflows/CI.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ jobs:
4040
components: rustfmt
4141

4242
- name: cargo fmt --check
43-
run: cargo fmt --all --check
43+
run: |
44+
if ! rustfmt --check --edition 2021 $(git ls-files '*.rs'); then
45+
printf "Please run \`rustfmt --edition 2021 \$(git ls-files '*.rs')\` to fix rustfmt errors.\nSee CONTRIBUTING.md for more details.\n" >&2
46+
exit 1
47+
fi
4448
4549
test:
4650
name: Test ${{ matrix.rust }} on ${{ matrix.os }}

CONTRIBUTING.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Contributing to Hyper
2+
3+
You want to contribute? You're awesome! Don't know where to start? Check the [list of easy issues](https://github.com/hyperium/hyper/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy).
4+
5+
[easy tag]: https://github.com/hyperium/hyper/issues?q=label%3AE-easy+is%3Aopen
6+
7+
8+
## [Pull Requests](./docs/PULL_REQUESTS.md)
9+
10+
- [Submitting a Pull Request](./docs/PULL_REQUESTS.md#submitting-a-pull-request)
11+
- [Commit Guidelines](./docs/COMMITS.md)
12+
13+
## Cargo fmt
14+
`cargo fmt --all` does not work in hyper. Please use the following commands:
15+
```txt
16+
# Mac or Linux
17+
rustfmt --check --edition 2018 $(git ls-files '*.rs')
18+
19+
# Powershell
20+
Get-ChildItem . -Filter "*.rs" -Recurse | foreach { rustfmt --check --edition 2018 $_.FullName }
21+
```

src/client/conn/http1.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ use tokio::io::{AsyncRead, AsyncWrite};
1010

1111
use super::super::dispatch;
1212
use crate::body::{Body, Incoming as IncomingBody};
13-
use crate::common::{
14-
task, Future, Pin, Poll,
15-
};
13+
use crate::common::{task, Future, Pin, Poll};
1614
use crate::proto;
1715
use crate::upgrade::Upgraded;
1816

@@ -319,10 +317,7 @@ impl Builder {
319317
/// Default is false.
320318
///
321319
/// [RFC 7230 Section 3.2.4.]: https://tools.ietf.org/html/rfc7230#section-3.2.4
322-
pub fn allow_spaces_after_header_name_in_responses(
323-
&mut self,
324-
enabled: bool,
325-
) -> &mut Builder {
320+
pub fn allow_spaces_after_header_name_in_responses(&mut self, enabled: bool) -> &mut Builder {
326321
self.h1_parser_config
327322
.allow_spaces_after_header_name_in_responses(enabled);
328323
self
@@ -360,10 +355,7 @@ impl Builder {
360355
/// Default is false.
361356
///
362357
/// [RFC 7230 Section 3.2.4.]: https://tools.ietf.org/html/rfc7230#section-3.2.4
363-
pub fn allow_obsolete_multiline_headers_in_responses(
364-
&mut self,
365-
enabled: bool,
366-
) -> &mut Builder {
358+
pub fn allow_obsolete_multiline_headers_in_responses(&mut self, enabled: bool) -> &mut Builder {
367359
self.h1_parser_config
368360
.allow_obsolete_multiline_headers_in_responses(enabled);
369361
self

src/client/conn/http2.rs

+7-14
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ pub struct SendRequest<B> {
2626

2727
impl<B> Clone for SendRequest<B> {
2828
fn clone(&self) -> SendRequest<B> {
29-
SendRequest { dispatch: self.dispatch.clone() }
29+
SendRequest {
30+
dispatch: self.dispatch.clone(),
31+
}
3032
}
3133
}
3234

@@ -57,10 +59,7 @@ pub struct Builder {
5759
///
5860
/// This is a shortcut for `Builder::new().handshake(io)`.
5961
/// See [`client::conn`](crate::client::conn) for more.
60-
pub async fn handshake<E, T, B>(
61-
exec: E,
62-
io: T,
63-
) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
62+
pub async fn handshake<E, T, B>(exec: E, io: T) -> crate::Result<(SendRequest<B>, Connection<T, B>)>
6463
where
6564
E: Executor<BoxSendFuture> + Send + Sync + 'static,
6665
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
@@ -243,7 +242,7 @@ where
243242
impl Builder {
244243
/// Creates a new connection builder.
245244
#[inline]
246-
pub fn new<E>(exec: E) -> Builder
245+
pub fn new<E>(exec: E) -> Builder
247246
where
248247
E: Executor<BoxSendFuture> + Send + Sync + 'static,
249248
{
@@ -284,10 +283,7 @@ impl Builder {
284283
/// Passing `None` will do nothing.
285284
///
286285
/// If not set, hyper will use a default.
287-
pub fn initial_connection_window_size(
288-
&mut self,
289-
sz: impl Into<Option<u32>>,
290-
) -> &mut Self {
286+
pub fn initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
291287
if let Some(sz) = sz.into() {
292288
self.h2_builder.adaptive_window = false;
293289
self.h2_builder.initial_conn_window_size = sz;
@@ -329,10 +325,7 @@ impl Builder {
329325
/// Pass `None` to disable HTTP2 keep-alive.
330326
///
331327
/// Default is currently disabled.
332-
pub fn keep_alive_interval(
333-
&mut self,
334-
interval: impl Into<Option<Duration>>,
335-
) -> &mut Self {
328+
pub fn keep_alive_interval(&mut self, interval: impl Into<Option<Duration>>) -> &mut Self {
336329
self.h2_builder.keep_alive_interval = interval.into();
337330
self
338331
}

src/client/conn/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,3 @@
5656
pub mod http1;
5757
#[cfg(feature = "http2")]
5858
pub mod http2;
59-

src/headers.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ pub(super) fn content_length_parse_all_values(values: ValueIter<'_, HeaderValue>
5353
return None;
5454
}
5555
} else {
56-
return None
56+
return None;
5757
}
5858
}
5959
} else {
60-
return None
60+
return None;
6161
}
6262
}
6363

64-
return content_length
64+
return content_length;
6565
}
6666

6767
fn from_digits(bytes: &[u8]) -> Option<u64> {
@@ -80,7 +80,7 @@ fn from_digits(bytes: &[u8]) -> Option<u64> {
8080
b'0'..=b'9' => {
8181
result = result.checked_mul(RADIX)?;
8282
result = result.checked_add((b - b'0') as u64)?;
83-
},
83+
}
8484
_ => {
8585
// not a DIGIT, get outta here!
8686
return None;

src/proto/h1/dispatch.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ pub(crate) trait Dispatch {
2828
self: Pin<&mut Self>,
2929
cx: &mut task::Context<'_>,
3030
) -> Poll<Option<Result<(Self::PollItem, Self::PollBody), Self::PollError>>>;
31-
fn recv_msg(&mut self, msg: crate::Result<(Self::RecvItem, IncomingBody)>) -> crate::Result<()>;
31+
fn recv_msg(&mut self, msg: crate::Result<(Self::RecvItem, IncomingBody)>)
32+
-> crate::Result<()>;
3233
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), ()>>;
3334
fn should_poll(&self) -> bool;
3435
}
@@ -249,7 +250,8 @@ where
249250
let body = match body_len {
250251
DecodedLength::ZERO => IncomingBody::empty(),
251252
other => {
252-
let (tx, rx) = IncomingBody::new_channel(other, wants.contains(Wants::EXPECT));
253+
let (tx, rx) =
254+
IncomingBody::new_channel(other, wants.contains(Wants::EXPECT));
253255
self.body_tx = Some(tx);
254256
rx
255257
}

src/proto/h2/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use tracing::{debug, trace, warn};
1313

1414
use super::{ping, H2Upgraded, PipeToSendStream, SendBuf};
1515
use crate::body::{Body, Incoming as IncomingBody};
16-
use crate::common::time::Time;
1716
use crate::client::dispatch::Callback;
17+
use crate::common::time::Time;
1818
use crate::common::{exec::Exec, task, Future, Never, Pin, Poll};
1919
use crate::ext::Protocol;
2020
use crate::headers;

src/proto/h2/mod.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ where
129129
match ready!(me.body_tx.poll_capacity(cx)) {
130130
Some(Ok(0)) => {}
131131
Some(Ok(_)) => break,
132-
Some(Err(e)) => {
133-
return Poll::Ready(Err(crate::Error::new_body_write(e)))
134-
}
132+
Some(Err(e)) => return Poll::Ready(Err(crate::Error::new_body_write(e))),
135133
None => {
136134
// None means the stream is no longer in a
137135
// streaming state, we either finished it
@@ -148,9 +146,7 @@ where
148146
.map_err(crate::Error::new_body_write)?
149147
{
150148
debug!("stream received RST_STREAM: {:?}", reason);
151-
return Poll::Ready(Err(crate::Error::new_body_write(::h2::Error::from(
152-
reason,
153-
))));
149+
return Poll::Ready(Err(crate::Error::new_body_write(::h2::Error::from(reason))));
154150
}
155151

156152
match ready!(me.stream.as_mut().poll_frame(cx)) {
@@ -365,14 +361,12 @@ where
365361
cx: &mut Context<'_>,
366362
) -> Poll<Result<(), io::Error>> {
367363
if self.send_stream.write(&[], true).is_ok() {
368-
return Poll::Ready(Ok(()))
364+
return Poll::Ready(Ok(()));
369365
}
370366

371367
Poll::Ready(Err(h2_to_io_error(
372368
match ready!(self.send_stream.poll_reset(cx)) {
373-
Ok(Reason::NO_ERROR) => {
374-
return Poll::Ready(Ok(()))
375-
}
369+
Ok(Reason::NO_ERROR) => return Poll::Ready(Ok(())),
376370
Ok(Reason::CANCEL) | Ok(Reason::STREAM_CLOSED) => {
377371
return Poll::Ready(Err(io::ErrorKind::BrokenPipe.into()))
378372
}

src/proto/h2/server.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ use tracing::{debug, trace, warn};
1313

1414
use super::{ping, PipeToSendStream, SendBuf};
1515
use crate::body::{Body, Incoming as IncomingBody};
16-
use crate::rt::bounds::Http2ConnExec;
1716
use crate::common::time::Time;
1817
use crate::common::{date, task, Future, Pin, Poll};
1918
use crate::ext::Protocol;
2019
use crate::headers;
2120
use crate::proto::h2::ping::Recorder;
2221
use crate::proto::h2::{H2Upgraded, UpgradedSendStream};
2322
use crate::proto::Dispatched;
23+
use crate::rt::bounds::Http2ConnExec;
2424
use crate::service::HttpService;
2525

2626
use crate::upgrade::{OnUpgrade, Pending, Upgraded};
27-
use crate::{Response};
27+
use crate::Response;
2828

2929
// Our defaults are chosen for the "majority" case, which usually are not
3030
// resource constrained, and so the spec default of 64kb can be too limiting

src/server/conn/http1.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ use tokio::io::{AsyncRead, AsyncWrite};
1010

1111
use crate::body::{Body, Incoming as IncomingBody};
1212
use crate::common::{task, Future, Pin, Poll, Unpin};
13-
use crate::{common::time::Time, rt::Timer};
1413
use crate::proto;
1514
use crate::service::HttpService;
15+
use crate::{common::time::Time, rt::Timer};
1616

17-
type Http1Dispatcher<T, B, S> =
18-
proto::h1::Dispatcher<proto::h1::dispatch::Server<S, IncomingBody>, B, T, proto::ServerTransaction>;
19-
17+
type Http1Dispatcher<T, B, S> = proto::h1::Dispatcher<
18+
proto::h1::dispatch::Server<S, IncomingBody>,
19+
B,
20+
T,
21+
proto::ServerTransaction,
22+
>;
2023

2124
pin_project_lite::pin_project! {
2225
/// A future binding an http1 connection with a Service.
@@ -31,7 +34,6 @@ pin_project_lite::pin_project! {
3134
}
3235
}
3336

34-
3537
/// A configuration builder for HTTP/1 server connections.
3638
#[derive(Clone, Debug)]
3739
pub struct Builder {
@@ -151,9 +153,7 @@ where
151153
let mut zelf = Some(self);
152154
futures_util::future::poll_fn(move |cx| {
153155
ready!(zelf.as_mut().unwrap().conn.poll_without_shutdown(cx))?;
154-
Poll::Ready(
155-
Ok(zelf.take().unwrap().into_parts())
156-
)
156+
Poll::Ready(Ok(zelf.take().unwrap().into_parts()))
157157
})
158158
}
159159

@@ -168,7 +168,6 @@ where
168168
}
169169
}
170170

171-
172171
impl<I, B, S> Future for Connection<I, S>
173172
where
174173
S: HttpService<IncomingBody, ResBody = B>,
@@ -194,7 +193,7 @@ where
194193
};
195194
return Poll::Ready(Ok(()));
196195
}
197-
Err(e) => Poll::Ready(Err(e)),
196+
Err(e) => Poll::Ready(Err(e)),
198197
}
199198
}
200199
}
@@ -389,9 +388,7 @@ impl Builder {
389388
}
390389
let sd = proto::h1::dispatch::Server::new(service);
391390
let proto = proto::h1::Dispatcher::new(sd, conn);
392-
Connection {
393-
conn: proto,
394-
}
391+
Connection { conn: proto }
395392
}
396393
}
397394

src/server/conn/http2.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ impl<E> Builder<E> {
132132
/// Passing `None` will do nothing.
133133
///
134134
/// If not set, hyper will use a default.
135-
pub fn initial_connection_window_size(
136-
&mut self,
137-
sz: impl Into<Option<u32>>,
138-
) -> &mut Self {
135+
pub fn initial_connection_window_size(&mut self, sz: impl Into<Option<u32>>) -> &mut Self {
139136
if let Some(sz) = sz.into() {
140137
self.h2_builder.adaptive_window = false;
141138
self.h2_builder.initial_conn_window_size = sz;
@@ -191,10 +188,7 @@ impl<E> Builder<E> {
191188
///
192189
/// # Cargo Feature
193190
///
194-
pub fn keep_alive_interval(
195-
&mut self,
196-
interval: impl Into<Option<Duration>>,
197-
) -> &mut Self {
191+
pub fn keep_alive_interval(&mut self, interval: impl Into<Option<Duration>>) -> &mut Self {
198192
self.h2_builder.keep_alive_interval = interval.into();
199193
self
200194
}

src/server/conn/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,3 @@
4949
pub mod http1;
5050
#[cfg(feature = "http2")]
5151
pub mod http2;
52-

src/server/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
//! concerns itself with. After you have a connection, you can handle HTTP over
88
//! it with the types in the [`conn`](conn) module.
99
pub mod conn;
10-

0 commit comments

Comments
 (0)