Skip to content

Commit 5628c21

Browse files
committed
Run rustfmt on bitreq to align it with workspace requirements
It appears `bitreq` had fallen out of sync with the workspace `rustfmt` requirements, so we run it here. Best reviewed with `--word-diff`
1 parent 8499dec commit 5628c21

File tree

7 files changed

+74
-42
lines changed

7 files changed

+74
-42
lines changed

bitreq/src/connection.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ use std::net::{TcpStream, ToSocketAddrs};
88
use std::pin::Pin;
99
use std::time::Instant;
1010

11-
#[cfg(feature = "async")]
12-
use tokio::io::{AsyncRead, AsyncWriteExt};
1311
#[cfg(all(feature = "async", feature = "proxy"))]
1412
use tokio::io::AsyncReadExt;
1513
#[cfg(feature = "async")]
14+
use tokio::io::{AsyncRead, AsyncWriteExt};
15+
#[cfg(feature = "async")]
1616
use tokio::net::TcpStream as AsyncTcpStream;
1717

1818
use crate::request::ParsedRequest;
@@ -481,7 +481,11 @@ macro_rules! redirect_utils {
481481
Destination($Connection),
482482
}
483483

484-
fn $get_redirect(mut connection: $Connection, status_code: i32, url: Option<&String>) -> $NextHop {
484+
fn $get_redirect(
485+
mut connection: $Connection,
486+
status_code: i32,
487+
url: Option<&String>,
488+
) -> $NextHop {
485489
match status_code {
486490
301 | 302 | 303 | 307 => {
487491
let url = match url {
@@ -510,8 +514,7 @@ macro_rules! redirect_utils {
510514
_ => $NextHop::Destination(connection),
511515
}
512516
}
513-
514-
}
517+
};
515518
}
516519

517520
redirect_utils!(get_redirect, NextHop, Connection, ResponseLazy);
@@ -544,8 +547,9 @@ where
544547
Ok(()) => thread.join().unwrap(),
545548
Err(err) => match err {
546549
RecvTimeoutError::Timeout => Err(Error::IoError(timeout_err())),
547-
RecvTimeoutError::Disconnected =>
548-
Err(Error::Other("request connection paniced")),
550+
RecvTimeoutError::Disconnected => {
551+
Err(Error::Other("request connection paniced"))
552+
}
549553
},
550554
}
551555
} else {

bitreq/src/connection/rustls_stream.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use webpki_roots::TLS_SERVER_ROOTS;
1414
#[cfg(feature = "async-https")]
1515
use tokio::io::AsyncWriteExt;
1616
#[cfg(feature = "async-https")]
17-
use tokio_rustls::{TlsConnector, client::TlsStream};
17+
use tokio_rustls::{client::TlsStream, TlsConnector};
1818

1919
#[cfg(feature = "async-https")]
2020
use super::{AsyncConnection, AsyncHttpStream};
@@ -89,7 +89,9 @@ pub(super) fn create_secured_stream(conn: &Connection) -> Result<HttpStream, Err
8989
pub type AsyncSecuredStream = TlsStream<tokio::net::TcpStream>;
9090

9191
#[cfg(feature = "async-https")]
92-
pub(super) async fn create_async_secured_stream(conn: &AsyncConnection) -> Result<AsyncHttpStream, Error> {
92+
pub(super) async fn create_async_secured_stream(
93+
conn: &AsyncConnection,
94+
) -> Result<AsyncHttpStream, Error> {
9395
// Rustls setup
9496
#[cfg(feature = "log")]
9597
log::trace!("Setting up TLS parameters for {}.", conn.request.url.host);

bitreq/src/error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,7 @@ impl error::Error for Error {
133133

134134
#[cfg(feature = "std")]
135135
impl From<io::Error> for Error {
136-
fn from(other: io::Error) -> Error { Error::IoError(other) }
136+
fn from(other: io::Error) -> Error {
137+
Error::IoError(other)
138+
}
137139
}

bitreq/src/request.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -512,39 +512,57 @@ impl ParsedRequest {
512512

513513
/// Alias for [Request::new](struct.Request.html#method.new) with `method` set to
514514
/// [Method::Get](enum.Method.html).
515-
pub fn get<T: Into<URL>>(url: T) -> Request { Request::new(Method::Get, url) }
515+
pub fn get<T: Into<URL>>(url: T) -> Request {
516+
Request::new(Method::Get, url)
517+
}
516518

517519
/// Alias for [Request::new](struct.Request.html#method.new) with `method` set to
518520
/// [Method::Head](enum.Method.html).
519-
pub fn head<T: Into<URL>>(url: T) -> Request { Request::new(Method::Head, url) }
521+
pub fn head<T: Into<URL>>(url: T) -> Request {
522+
Request::new(Method::Head, url)
523+
}
520524

521525
/// Alias for [Request::new](struct.Request.html#method.new) with `method` set to
522526
/// [Method::Post](enum.Method.html).
523-
pub fn post<T: Into<URL>>(url: T) -> Request { Request::new(Method::Post, url) }
527+
pub fn post<T: Into<URL>>(url: T) -> Request {
528+
Request::new(Method::Post, url)
529+
}
524530

525531
/// Alias for [Request::new](struct.Request.html#method.new) with `method` set to
526532
/// [Method::Put](enum.Method.html).
527-
pub fn put<T: Into<URL>>(url: T) -> Request { Request::new(Method::Put, url) }
533+
pub fn put<T: Into<URL>>(url: T) -> Request {
534+
Request::new(Method::Put, url)
535+
}
528536

529537
/// Alias for [Request::new](struct.Request.html#method.new) with `method` set to
530538
/// [Method::Delete](enum.Method.html).
531-
pub fn delete<T: Into<URL>>(url: T) -> Request { Request::new(Method::Delete, url) }
539+
pub fn delete<T: Into<URL>>(url: T) -> Request {
540+
Request::new(Method::Delete, url)
541+
}
532542

533543
/// Alias for [Request::new](struct.Request.html#method.new) with `method` set to
534544
/// [Method::Connect](enum.Method.html).
535-
pub fn connect<T: Into<URL>>(url: T) -> Request { Request::new(Method::Connect, url) }
545+
pub fn connect<T: Into<URL>>(url: T) -> Request {
546+
Request::new(Method::Connect, url)
547+
}
536548

537549
/// Alias for [Request::new](struct.Request.html#method.new) with `method` set to
538550
/// [Method::Options](enum.Method.html).
539-
pub fn options<T: Into<URL>>(url: T) -> Request { Request::new(Method::Options, url) }
551+
pub fn options<T: Into<URL>>(url: T) -> Request {
552+
Request::new(Method::Options, url)
553+
}
540554

541555
/// Alias for [Request::new](struct.Request.html#method.new) with `method` set to
542556
/// [Method::Trace](enum.Method.html).
543-
pub fn trace<T: Into<URL>>(url: T) -> Request { Request::new(Method::Trace, url) }
557+
pub fn trace<T: Into<URL>>(url: T) -> Request {
558+
Request::new(Method::Trace, url)
559+
}
544560

545561
/// Alias for [Request::new](struct.Request.html#method.new) with `method` set to
546562
/// [Method::Patch](enum.Method.html).
547-
pub fn patch<T: Into<URL>>(url: T) -> Request { Request::new(Method::Patch, url) }
563+
pub fn patch<T: Into<URL>>(url: T) -> Request {
564+
Request::new(Method::Patch, url)
565+
}
548566

549567
#[cfg(test)]
550568
#[cfg(feature = "std")]

bitreq/src/response.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use alloc::collections::BTreeMap;
22
use core::str;
3-
#[cfg(feature = "std")]
4-
use std::io::{self, BufReader, Bytes, Read};
53
#[cfg(feature = "async")]
64
use std::future::Future;
5+
#[cfg(feature = "std")]
6+
use std::io::{self, BufReader, Bytes, Read};
77

88
#[cfg(feature = "async")]
99
use tokio::io::{AsyncRead, AsyncReadExt};
@@ -96,9 +96,7 @@ impl Response {
9696
if !is_head && status_code != 204 && status_code != 304 {
9797
match state {
9898
EndOnClose => {
99-
while let Some(byte_result) =
100-
read_until_closed_async(&mut stream).await
101-
{
99+
while let Some(byte_result) = read_until_closed_async(&mut stream).await {
102100
let (byte, length) = byte_result?;
103101
body.reserve(length);
104102
body.push(byte);
@@ -179,7 +177,9 @@ impl Response {
179177
/// # #[cfg(not(feature = "std"))]
180178
/// # fn main() -> Result<(), Box<dyn std::error::Error>> { Ok(()) }
181179
/// ```
182-
pub fn as_bytes(&self) -> &[u8] { &self.body }
180+
pub fn as_bytes(&self) -> &[u8] {
181+
&self.body
182+
}
183183

184184
/// Turns the `Response` into the inner `Vec<u8>`, the bytes that
185185
/// make up the response's body. If you just need a `&[u8]`, use
@@ -199,7 +199,9 @@ impl Response {
199199
/// # #[cfg(not(feature = "std"))]
200200
/// # fn main() -> Result<(), Box<dyn std::error::Error>> { Ok(()) }
201201
/// ```
202-
pub fn into_bytes(self) -> Vec<u8> { self.body }
202+
pub fn into_bytes(self) -> Vec<u8> {
203+
self.body
204+
}
203205

204206
/// Converts JSON body to a `struct` using Serde.
205207
///
@@ -349,15 +351,16 @@ impl Iterator for ResponseLazy {
349351
match self.state {
350352
EndOnClose => read_until_closed(&mut self.stream),
351353
ContentLength(ref mut length) => read_with_content_length(&mut self.stream, length),
352-
Chunked(ref mut expecting_chunks, ref mut length, ref mut content_length) =>
354+
Chunked(ref mut expecting_chunks, ref mut length, ref mut content_length) => {
353355
read_chunked(
354356
&mut self.stream,
355357
&mut self.headers,
356358
expecting_chunks,
357359
length,
358360
content_length,
359361
self.max_trailing_headers_size,
360-
),
362+
)
363+
}
361364
}
362365
}
363366
}
@@ -435,9 +438,7 @@ trait AsyncIteratorReadExt {
435438
#[cfg(feature = "async")]
436439
impl<T: AsyncReadExt + Unpin> AsyncIteratorReadExt for T {
437440
fn next(&mut self) -> impl Future<Output = Option<Result<u8, io::Error>>> {
438-
async {
439-
Some(self.read_u8().await)
440-
}
441+
async { Some(self.read_u8().await) }
441442
}
442443
}
443444

bitreq/tests/main.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ async fn test_json_using_serde() {
2424

2525
setup();
2626
let original_json: serde_json::Value = serde_json::from_str(JSON_SRC).unwrap();
27-
let response = make_request(bitreq::post(url("/echo")).with_json(&original_json).unwrap()).await;
27+
let response =
28+
make_request(bitreq::post(url("/echo")).with_json(&original_json).unwrap()).await;
2829
let actual_json: serde_json::Value = response.json().unwrap();
2930
assert_eq!(actual_json, original_json);
3031
}
@@ -56,10 +57,9 @@ async fn test_headers() {
5657
async fn test_custom_method() {
5758
use bitreq::Method;
5859
setup();
59-
let body = get_body(
60-
bitreq::Request::new(Method::Custom("GET".to_string()), url("/a")).with_body("Q"),
61-
)
62-
.await;
60+
let body =
61+
get_body(bitreq::Request::new(Method::Custom("GET".to_string()), url("/a")).with_body("Q"))
62+
.await;
6363
assert_eq!("j: Q", body);
6464
}
6565

@@ -176,7 +176,8 @@ async fn test_patch() {
176176
#[tokio::test]
177177
async fn tcp_connect_timeout() {
178178
let _listener = std::net::TcpListener::bind("127.0.0.1:32162").unwrap();
179-
let request = bitreq::Request::new(bitreq::Method::Get, "http://127.0.0.1:32162").with_timeout(1);
179+
let request =
180+
bitreq::Request::new(bitreq::Method::Get, "http://127.0.0.1:32162").with_timeout(1);
180181
let resp = maybe_make_request(request).await;
181182
assert!(resp.is_err());
182183
if let Some(bitreq::Error::IoError(err)) = resp.err() {

bitreq/tests/setup.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,13 @@ pub fn setup() {
175175
});
176176
}
177177

178-
pub fn url(req: &str) -> String { format!("http://localhost:35562{}", req) }
178+
pub fn url(req: &str) -> String {
179+
format!("http://localhost:35562{}", req)
180+
}
179181

180-
pub async fn maybe_make_request(request: bitreq::Request) -> Result<bitreq::Response, bitreq::Error> {
182+
pub async fn maybe_make_request(
183+
request: bitreq::Request,
184+
) -> Result<bitreq::Response, bitreq::Error> {
181185
let response = request.clone().send();
182186
let lazy_response = request.clone().send_lazy();
183187
match (&response, lazy_response) {
@@ -187,7 +191,7 @@ pub async fn maybe_make_request(request: bitreq::Request) -> Result<bitreq::Resp
187191
let mut lazy_bytes = Vec::new();
188192
lazy_resp.read_to_end(&mut lazy_bytes).unwrap();
189193
assert_eq!(lazy_bytes, resp.as_bytes());
190-
},
194+
}
191195
(Err(e), Err(lazy_e)) => assert_eq!(format!("{e:?}"), format!("{lazy_e:?}")),
192196
(res, lazy_res) => panic!("{res:?} != {}", lazy_res.is_err()),
193197
}
@@ -208,7 +212,7 @@ pub async fn maybe_make_request(request: bitreq::Request) -> Result<bitreq::Resp
208212
assert_eq!(async_resp.status_code, resp.status_code);
209213
assert_eq!(async_resp.reason_phrase, resp.reason_phrase);
210214
assert_eq!(async_resp.as_bytes(), resp.as_bytes());
211-
},
215+
}
212216
(Err(e), Err(async_e)) => assert_eq!(format!("{e:?}"), format!("{async_e:?}")),
213217
(res, async_res) => panic!("{res:?} != {async_res:?}"),
214218
}
@@ -219,7 +223,7 @@ pub async fn maybe_make_request(request: bitreq::Request) -> Result<bitreq::Resp
219223
let mut lazy_bytes = Vec::new();
220224
lazy_resp.read_to_end(&mut lazy_bytes).unwrap();
221225
assert_eq!(lazy_bytes, resp.as_bytes());
222-
},
226+
}
223227
(Err(e), Err(lazy_e)) => assert_eq!(format!("{e:?}"), format!("{lazy_e:?}")),
224228
(res, lazy_res) => panic!("{res:?} != {}", lazy_res.is_err()),
225229
}

0 commit comments

Comments
 (0)