Skip to content

Commit 2d6eb24

Browse files
authored
chore: Inline format args (#2024)
This makes the code a bit easier to read, and might result in a few minor perf optimizations (e.g. if Display trait is implemented, it might be better to make it part of the formatting)
1 parent 05c3982 commit 2d6eb24

36 files changed

+86
-93
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3838
.await?
3939
.json::<HashMap<String, String>>()
4040
.await?;
41-
println!("{:#?}", resp);
41+
println!("{resp:#?}");
4242
Ok(())
4343
}
4444
```
@@ -58,7 +58,7 @@ use std::collections::HashMap;
5858
fn main() -> Result<(), Box<dyn std::error::Error>> {
5959
let resp = reqwest::blocking::get("https://httpbin.org/ip")?
6060
.json::<HashMap<String, String>>()?;
61-
println!("{:#?}", resp);
61+
println!("{resp:#?}");
6262
Ok(())
6363
}
6464
```

examples/blocking.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
1313
}
1414
};
1515

16-
eprintln!("Fetching {:?}...", url);
16+
eprintln!("Fetching {url:?}...");
1717

1818
// reqwest::blocking::get() is a convenience function.
1919
//

examples/h3_simple.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async fn main() -> Result<(), reqwest::Error> {
2929
}
3030
};
3131

32-
eprintln!("Fetching {:?}...", url);
32+
eprintln!("Fetching {url:?}...");
3333

3434
let res = get(url).await?;
3535

@@ -38,7 +38,7 @@ async fn main() -> Result<(), reqwest::Error> {
3838

3939
let body = res.text().await?;
4040

41-
println!("{}", body);
41+
println!("{body}");
4242

4343
Ok(())
4444
}

examples/json_dynamic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async fn main() -> Result<(), reqwest::Error> {
2121
.json()
2222
.await?;
2323

24-
println!("{:#?}", echo_json);
24+
println!("{echo_json:#?}");
2525
// Object(
2626
// {
2727
// "body": String(

examples/json_typed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async fn main() -> Result<(), reqwest::Error> {
3535
.json()
3636
.await?;
3737

38-
println!("{:#?}", new_post);
38+
println!("{new_post:#?}");
3939
// Post {
4040
// id: Some(
4141
// 101

examples/simple.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ async fn main() -> Result<(), reqwest::Error> {
1414
"https://hyper.rs".into()
1515
};
1616

17-
eprintln!("Fetching {:?}...", url);
17+
eprintln!("Fetching {url:?}...");
1818

1919
// reqwest::get() is a convenience function.
2020
//
@@ -27,7 +27,7 @@ async fn main() -> Result<(), reqwest::Error> {
2727

2828
let body = res.text().await?;
2929

30-
println!("{}", body);
30+
println!("{body}");
3131

3232
Ok(())
3333
}

examples/tor_socks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async fn main() -> Result<(), reqwest::Error> {
1717

1818
let text = res.text().await?;
1919
let is_tor = text.contains("Congratulations. This browser is configured to use Tor.");
20-
println!("Is Tor: {}", is_tor);
20+
println!("Is Tor: {is_tor}");
2121
assert!(is_tor);
2222

2323
Ok(())

src/async_impl/client.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -494,9 +494,7 @@ impl ClientBuilder {
494494
Err(err) => {
495495
invalid_count += 1;
496496
log::warn!(
497-
"rustls failed to parse DER certificate {:?} {:?}",
498-
&err,
499-
&cert
497+
"rustls failed to parse DER certificate {err:?} {cert:?}"
500498
);
501499
}
502500
}
@@ -2164,7 +2162,7 @@ impl PendingRequest {
21642162
return false;
21652163
}
21662164

2167-
trace!("can retry {:?}", err);
2165+
trace!("can retry {err:?}");
21682166

21692167
let body = match self.body {
21702168
Some(Some(ref body)) => Body::reusable(body.clone()),
@@ -2220,7 +2218,7 @@ fn is_retryable_error(err: &(dyn std::error::Error + 'static)) -> bool {
22202218
#[cfg(feature = "http3")]
22212219
if let Some(cause) = err.source() {
22222220
if let Some(err) = cause.downcast_ref::<h3::Error>() {
2223-
debug!("determining if HTTP/3 error {} can be retried", err);
2221+
debug!("determining if HTTP/3 error {err} can be retried");
22242222
// TODO: Does h3 provide an API for checking the error?
22252223
return err.to_string().as_str() == "timeout";
22262224
}
@@ -2370,7 +2368,7 @@ impl Future for PendingRequest {
23702368
});
23712369

23722370
if loc.is_none() {
2373-
debug!("Location header had invalid URI: {:?}", val);
2371+
debug!("Location header had invalid URI: {val:?}");
23742372
}
23752373
loc
23762374
});
@@ -2452,7 +2450,7 @@ impl Future for PendingRequest {
24522450
continue;
24532451
}
24542452
redirect::ActionKind::Stop => {
2455-
debug!("redirect policy disallowed redirection to '{}'", loc);
2453+
debug!("redirect policy disallowed redirection to '{loc}'");
24562454
}
24572455
redirect::ActionKind::Error(err) => {
24582456
return Poll::Ready(Err(crate::error::redirect(err, self.url.clone())));

src/async_impl/decoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Decoder {
169169
if is_content_encoded {
170170
if let Some(content_length) = headers.get(CONTENT_LENGTH) {
171171
if content_length == "0" {
172-
warn!("{} response with content-length of 0", encoding_str);
172+
warn!("{encoding_str} response with content-length of 0");
173173
is_content_encoded = false;
174174
}
175175
}

src/async_impl/h3_client/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ impl H3Client {
3333

3434
async fn get_pooled_client(&mut self, key: Key) -> Result<PoolClient, BoxError> {
3535
if let Some(client) = self.pool.try_pool(&key) {
36-
trace!("getting client from pool with key {:?}", key);
36+
trace!("getting client from pool with key {key:?}");
3737
return Ok(client);
3838
}
3939

40-
trace!("did not find connection {:?} in pool so connecting...", key);
40+
trace!("did not find connection {key:?} in pool so connecting...");
4141

4242
let dest = pool::domain_as_uri(key.clone());
4343
self.pool.connecting(key.clone())?;

src/async_impl/h3_client/pool.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Pool {
3737
pub fn connecting(&self, key: Key) -> Result<(), BoxError> {
3838
let mut inner = self.inner.lock().unwrap();
3939
if !inner.connecting.insert(key.clone()) {
40-
return Err(format!("HTTP/3 connecting already in progress for {:?}", key).into());
40+
return Err(format!("HTTP/3 connecting already in progress for {key:?}").into());
4141
}
4242
return Ok(());
4343
}
@@ -77,7 +77,7 @@ impl Pool {
7777
let (close_tx, close_rx) = std::sync::mpsc::channel();
7878
tokio::spawn(async move {
7979
if let Err(e) = future::poll_fn(|cx| driver.poll_close(cx)).await {
80-
trace!("poll_close returned error {:?}", e);
80+
trace!("poll_close returned error {e:?}");
8181
close_tx.send(e).ok();
8282
}
8383
});
@@ -105,7 +105,7 @@ struct PoolInner {
105105
impl PoolInner {
106106
fn insert(&mut self, key: Key, conn: PoolConnection) {
107107
if self.idle_conns.contains_key(&key) {
108-
trace!("connection already exists for key {:?}", key);
108+
trace!("connection already exists for key {key:?}");
109109
}
110110

111111
self.idle_conns.insert(key, conn);

src/async_impl/multipart.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ fn gen_boundary() -> String {
520520
let c = random();
521521
let d = random();
522522

523-
format!("{:016x}-{:016x}-{:016x}-{:016x}", a, b, c, d)
523+
format!("{a:016x}-{b:016x}-{c:016x}-{d:016x}")
524524
}
525525

526526
#[cfg(test)]
@@ -597,7 +597,7 @@ mod tests {
597597
"START REAL\n{}\nEND REAL",
598598
std::str::from_utf8(&out).unwrap()
599599
);
600-
println!("START EXPECTED\n{}\nEND EXPECTED", expected);
600+
println!("START EXPECTED\n{expected}\nEND EXPECTED");
601601
assert_eq!(std::str::from_utf8(&out).unwrap(), expected);
602602
}
603603

@@ -629,7 +629,7 @@ mod tests {
629629
"START REAL\n{}\nEND REAL",
630630
std::str::from_utf8(&out).unwrap()
631631
);
632-
println!("START EXPECTED\n{}\nEND EXPECTED", expected);
632+
println!("START EXPECTED\n{expected}\nEND EXPECTED");
633633
assert_eq!(std::str::from_utf8(&out).unwrap(), expected);
634634
}
635635

src/async_impl/request.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl RequestBuilder {
266266
where
267267
T: fmt::Display,
268268
{
269-
let header_value = format!("Bearer {}", token);
269+
let header_value = format!("Bearer {token}");
270270
self.header_sensitive(crate::header::AUTHORIZATION, header_value, true)
271271
}
272272

src/async_impl/response.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl Response {
140140
/// .text()
141141
/// .await?;
142142
///
143-
/// println!("text: {:?}", content);
143+
/// println!("text: {content:?}");
144144
/// # Ok(())
145145
/// # }
146146
/// ```
@@ -169,7 +169,7 @@ impl Response {
169169
/// .text_with_charset("utf-8")
170170
/// .await?;
171171
///
172-
/// println!("text: {:?}", content);
172+
/// println!("text: {content:?}");
173173
/// # Ok(())
174174
/// # }
175175
/// ```
@@ -251,7 +251,7 @@ impl Response {
251251
/// .bytes()
252252
/// .await?;
253253
///
254-
/// println!("bytes: {:?}", bytes);
254+
/// println!("bytes: {bytes:?}");
255255
/// # Ok(())
256256
/// # }
257257
/// ```
@@ -270,7 +270,7 @@ impl Response {
270270
/// let mut res = reqwest::get("https://hyper.rs").await?;
271271
///
272272
/// while let Some(chunk) = res.chunk().await? {
273-
/// println!("Chunk: {:?}", chunk);
273+
/// println!("Chunk: {chunk:?}");
274274
/// }
275275
/// # Ok(())
276276
/// # }

src/blocking/client.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1014,11 +1014,11 @@ impl Drop for InnerClientHandle {
10141014
.map(|h| h.thread().id())
10151015
.expect("thread not dropped yet");
10161016

1017-
trace!("closing runtime thread ({:?})", id);
1017+
trace!("closing runtime thread ({id:?})");
10181018
self.tx.take();
1019-
trace!("signaled close for runtime thread ({:?})", id);
1019+
trace!("signaled close for runtime thread ({id:?})");
10201020
self.thread.take().map(|h| h.join());
1021-
trace!("closed runtime thread ({:?})", id);
1021+
trace!("closed runtime thread ({id:?})");
10221022
}
10231023
}
10241024

@@ -1039,7 +1039,7 @@ impl ClientHandle {
10391039
{
10401040
Err(e) => {
10411041
if let Err(e) = spawn_tx.send(Err(e)) {
1042-
error!("Failed to communicate runtime creation failure: {:?}", e);
1042+
error!("Failed to communicate runtime creation failure: {e:?}");
10431043
}
10441044
return;
10451045
}
@@ -1050,14 +1050,14 @@ impl ClientHandle {
10501050
let client = match builder.build() {
10511051
Err(e) => {
10521052
if let Err(e) = spawn_tx.send(Err(e)) {
1053-
error!("Failed to communicate client creation failure: {:?}", e);
1053+
error!("Failed to communicate client creation failure: {e:?}");
10541054
}
10551055
return;
10561056
}
10571057
Ok(v) => v,
10581058
};
10591059
if let Err(e) = spawn_tx.send(Ok(())) {
1060-
error!("Failed to communicate successful startup: {:?}", e);
1060+
error!("Failed to communicate successful startup: {e:?}");
10611061
return;
10621062
}
10631063

src/blocking/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//! let body = reqwest::blocking::get("https://www.rust-lang.org")?
2626
//! .text()?;
2727
//!
28-
//! println!("body = {:?}", body);
28+
//! println!("body = {body:?}");
2929
//! # Ok(())
3030
//! # }
3131
//! ```

src/blocking/multipart.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ mod tests {
420420
"START REAL\n{}\nEND REAL",
421421
std::str::from_utf8(&output).unwrap()
422422
);
423-
println!("START EXPECTED\n{}\nEND EXPECTED", expected);
423+
println!("START EXPECTED\n{expected}\nEND EXPECTED");
424424
assert_eq!(std::str::from_utf8(&output).unwrap(), expected);
425425
assert!(length.is_none());
426426
}
@@ -450,7 +450,7 @@ mod tests {
450450
"START REAL\n{}\nEND REAL",
451451
std::str::from_utf8(&output).unwrap()
452452
);
453-
println!("START EXPECTED\n{}\nEND EXPECTED", expected);
453+
println!("START EXPECTED\n{expected}\nEND EXPECTED");
454454
assert_eq!(std::str::from_utf8(&output).unwrap(), expected);
455455
assert_eq!(length.unwrap(), expected.len() as u64);
456456
}
@@ -477,7 +477,7 @@ mod tests {
477477
"START REAL\n{}\nEND REAL",
478478
std::str::from_utf8(&output).unwrap()
479479
);
480-
println!("START EXPECTED\n{}\nEND EXPECTED", expected);
480+
println!("START EXPECTED\n{expected}\nEND EXPECTED");
481481
assert_eq!(std::str::from_utf8(&output).unwrap(), expected);
482482
}
483483
}

src/blocking/request.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl RequestBuilder {
284284
where
285285
T: fmt::Display,
286286
{
287-
let header_value = format!("Bearer {}", token);
287+
let header_value = format!("Bearer {token}");
288288
self.header_sensitive(crate::header::AUTHORIZATION, &*header_value, true)
289289
}
290290

src/blocking/response.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Response {
8383
/// StatusCode::PAYLOAD_TOO_LARGE => {
8484
/// println!("Request payload is too large!");
8585
/// }
86-
/// s => println!("Received response status: {:?}", s),
86+
/// s => println!("Received response status: {s:?}"),
8787
/// };
8888
/// # Ok(())
8989
/// # }
@@ -252,7 +252,7 @@ impl Response {
252252
/// # fn run() -> Result<(), Box<dyn std::error::Error>> {
253253
/// let bytes = reqwest::blocking::get("http://httpbin.org/ip")?.bytes()?;
254254
///
255-
/// println!("bytes: {:?}", bytes);
255+
/// println!("bytes: {bytes:?}");
256256
/// # Ok(())
257257
/// # }
258258
/// ```

src/blocking/wait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ where
1313
enter();
1414

1515
let deadline = timeout.map(|d| {
16-
log::trace!("wait at most {:?}", d);
16+
log::trace!("wait at most {d:?}");
1717
Instant::now() + d
1818
});
1919

0 commit comments

Comments
 (0)