Skip to content

Commit

Permalink
chore: Inline format args (#2024)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
nyurik authored Feb 5, 2024
1 parent 05c3982 commit 2d6eb24
Show file tree
Hide file tree
Showing 36 changed files with 86 additions and 93 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.await?
.json::<HashMap<String, String>>()
.await?;
println!("{:#?}", resp);
println!("{resp:#?}");
Ok(())
}
```
Expand All @@ -58,7 +58,7 @@ use std::collections::HashMap;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let resp = reqwest::blocking::get("https://httpbin.org/ip")?
.json::<HashMap<String, String>>()?;
println!("{:#?}", resp);
println!("{resp:#?}");
Ok(())
}
```
Expand Down
2 changes: 1 addition & 1 deletion examples/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
};

eprintln!("Fetching {:?}...", url);
eprintln!("Fetching {url:?}...");

// reqwest::blocking::get() is a convenience function.
//
Expand Down
4 changes: 2 additions & 2 deletions examples/h3_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async fn main() -> Result<(), reqwest::Error> {
}
};

eprintln!("Fetching {:?}...", url);
eprintln!("Fetching {url:?}...");

let res = get(url).await?;

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

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

println!("{}", body);
println!("{body}");

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/json_dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async fn main() -> Result<(), reqwest::Error> {
.json()
.await?;

println!("{:#?}", echo_json);
println!("{echo_json:#?}");
// Object(
// {
// "body": String(
Expand Down
2 changes: 1 addition & 1 deletion examples/json_typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn main() -> Result<(), reqwest::Error> {
.json()
.await?;

println!("{:#?}", new_post);
println!("{new_post:#?}");
// Post {
// id: Some(
// 101
Expand Down
4 changes: 2 additions & 2 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async fn main() -> Result<(), reqwest::Error> {
"https://hyper.rs".into()
};

eprintln!("Fetching {:?}...", url);
eprintln!("Fetching {url:?}...");

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

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

println!("{}", body);
println!("{body}");

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion examples/tor_socks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn main() -> Result<(), reqwest::Error> {

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

Ok(())
Expand Down
12 changes: 5 additions & 7 deletions src/async_impl/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,7 @@ impl ClientBuilder {
Err(err) => {
invalid_count += 1;
log::warn!(
"rustls failed to parse DER certificate {:?} {:?}",
&err,
&cert
"rustls failed to parse DER certificate {err:?} {cert:?}"
);
}
}
Expand Down Expand Up @@ -2164,7 +2162,7 @@ impl PendingRequest {
return false;
}

trace!("can retry {:?}", err);
trace!("can retry {err:?}");

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

if loc.is_none() {
debug!("Location header had invalid URI: {:?}", val);
debug!("Location header had invalid URI: {val:?}");
}
loc
});
Expand Down Expand Up @@ -2452,7 +2450,7 @@ impl Future for PendingRequest {
continue;
}
redirect::ActionKind::Stop => {
debug!("redirect policy disallowed redirection to '{}'", loc);
debug!("redirect policy disallowed redirection to '{loc}'");
}
redirect::ActionKind::Error(err) => {
return Poll::Ready(Err(crate::error::redirect(err, self.url.clone())));
Expand Down
2 changes: 1 addition & 1 deletion src/async_impl/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ impl Decoder {
if is_content_encoded {
if let Some(content_length) = headers.get(CONTENT_LENGTH) {
if content_length == "0" {
warn!("{} response with content-length of 0", encoding_str);
warn!("{encoding_str} response with content-length of 0");
is_content_encoded = false;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/async_impl/h3_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ impl H3Client {

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

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

let dest = pool::domain_as_uri(key.clone());
self.pool.connecting(key.clone())?;
Expand Down
6 changes: 3 additions & 3 deletions src/async_impl/h3_client/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Pool {
pub fn connecting(&self, key: Key) -> Result<(), BoxError> {
let mut inner = self.inner.lock().unwrap();
if !inner.connecting.insert(key.clone()) {
return Err(format!("HTTP/3 connecting already in progress for {:?}", key).into());
return Err(format!("HTTP/3 connecting already in progress for {key:?}").into());
}
return Ok(());
}
Expand Down Expand Up @@ -77,7 +77,7 @@ impl Pool {
let (close_tx, close_rx) = std::sync::mpsc::channel();
tokio::spawn(async move {
if let Err(e) = future::poll_fn(|cx| driver.poll_close(cx)).await {
trace!("poll_close returned error {:?}", e);
trace!("poll_close returned error {e:?}");
close_tx.send(e).ok();
}
});
Expand Down Expand Up @@ -105,7 +105,7 @@ struct PoolInner {
impl PoolInner {
fn insert(&mut self, key: Key, conn: PoolConnection) {
if self.idle_conns.contains_key(&key) {
trace!("connection already exists for key {:?}", key);
trace!("connection already exists for key {key:?}");
}

self.idle_conns.insert(key, conn);
Expand Down
6 changes: 3 additions & 3 deletions src/async_impl/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ fn gen_boundary() -> String {
let c = random();
let d = random();

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

#[cfg(test)]
Expand Down Expand Up @@ -597,7 +597,7 @@ mod tests {
"START REAL\n{}\nEND REAL",
std::str::from_utf8(&out).unwrap()
);
println!("START EXPECTED\n{}\nEND EXPECTED", expected);
println!("START EXPECTED\n{expected}\nEND EXPECTED");
assert_eq!(std::str::from_utf8(&out).unwrap(), expected);
}

Expand Down Expand Up @@ -629,7 +629,7 @@ mod tests {
"START REAL\n{}\nEND REAL",
std::str::from_utf8(&out).unwrap()
);
println!("START EXPECTED\n{}\nEND EXPECTED", expected);
println!("START EXPECTED\n{expected}\nEND EXPECTED");
assert_eq!(std::str::from_utf8(&out).unwrap(), expected);
}

Expand Down
2 changes: 1 addition & 1 deletion src/async_impl/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl RequestBuilder {
where
T: fmt::Display,
{
let header_value = format!("Bearer {}", token);
let header_value = format!("Bearer {token}");
self.header_sensitive(crate::header::AUTHORIZATION, header_value, true)
}

Expand Down
8 changes: 4 additions & 4 deletions src/async_impl/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl Response {
/// .text()
/// .await?;
///
/// println!("text: {:?}", content);
/// println!("text: {content:?}");
/// # Ok(())
/// # }
/// ```
Expand Down Expand Up @@ -169,7 +169,7 @@ impl Response {
/// .text_with_charset("utf-8")
/// .await?;
///
/// println!("text: {:?}", content);
/// println!("text: {content:?}");
/// # Ok(())
/// # }
/// ```
Expand Down Expand Up @@ -251,7 +251,7 @@ impl Response {
/// .bytes()
/// .await?;
///
/// println!("bytes: {:?}", bytes);
/// println!("bytes: {bytes:?}");
/// # Ok(())
/// # }
/// ```
Expand All @@ -270,7 +270,7 @@ impl Response {
/// let mut res = reqwest::get("https://hyper.rs").await?;
///
/// while let Some(chunk) = res.chunk().await? {
/// println!("Chunk: {:?}", chunk);
/// println!("Chunk: {chunk:?}");
/// }
/// # Ok(())
/// # }
Expand Down
12 changes: 6 additions & 6 deletions src/blocking/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,11 +1014,11 @@ impl Drop for InnerClientHandle {
.map(|h| h.thread().id())
.expect("thread not dropped yet");

trace!("closing runtime thread ({:?})", id);
trace!("closing runtime thread ({id:?})");
self.tx.take();
trace!("signaled close for runtime thread ({:?})", id);
trace!("signaled close for runtime thread ({id:?})");
self.thread.take().map(|h| h.join());
trace!("closed runtime thread ({:?})", id);
trace!("closed runtime thread ({id:?})");
}
}

Expand All @@ -1039,7 +1039,7 @@ impl ClientHandle {
{
Err(e) => {
if let Err(e) = spawn_tx.send(Err(e)) {
error!("Failed to communicate runtime creation failure: {:?}", e);
error!("Failed to communicate runtime creation failure: {e:?}");
}
return;
}
Expand All @@ -1050,14 +1050,14 @@ impl ClientHandle {
let client = match builder.build() {
Err(e) => {
if let Err(e) = spawn_tx.send(Err(e)) {
error!("Failed to communicate client creation failure: {:?}", e);
error!("Failed to communicate client creation failure: {e:?}");
}
return;
}
Ok(v) => v,
};
if let Err(e) = spawn_tx.send(Ok(())) {
error!("Failed to communicate successful startup: {:?}", e);
error!("Failed to communicate successful startup: {e:?}");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/blocking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
//! let body = reqwest::blocking::get("https://www.rust-lang.org")?
//! .text()?;
//!
//! println!("body = {:?}", body);
//! println!("body = {body:?}");
//! # Ok(())
//! # }
//! ```
Expand Down
6 changes: 3 additions & 3 deletions src/blocking/multipart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ mod tests {
"START REAL\n{}\nEND REAL",
std::str::from_utf8(&output).unwrap()
);
println!("START EXPECTED\n{}\nEND EXPECTED", expected);
println!("START EXPECTED\n{expected}\nEND EXPECTED");
assert_eq!(std::str::from_utf8(&output).unwrap(), expected);
assert!(length.is_none());
}
Expand Down Expand Up @@ -450,7 +450,7 @@ mod tests {
"START REAL\n{}\nEND REAL",
std::str::from_utf8(&output).unwrap()
);
println!("START EXPECTED\n{}\nEND EXPECTED", expected);
println!("START EXPECTED\n{expected}\nEND EXPECTED");
assert_eq!(std::str::from_utf8(&output).unwrap(), expected);
assert_eq!(length.unwrap(), expected.len() as u64);
}
Expand All @@ -477,7 +477,7 @@ mod tests {
"START REAL\n{}\nEND REAL",
std::str::from_utf8(&output).unwrap()
);
println!("START EXPECTED\n{}\nEND EXPECTED", expected);
println!("START EXPECTED\n{expected}\nEND EXPECTED");
assert_eq!(std::str::from_utf8(&output).unwrap(), expected);
}
}
2 changes: 1 addition & 1 deletion src/blocking/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ impl RequestBuilder {
where
T: fmt::Display,
{
let header_value = format!("Bearer {}", token);
let header_value = format!("Bearer {token}");
self.header_sensitive(crate::header::AUTHORIZATION, &*header_value, true)
}

Expand Down
4 changes: 2 additions & 2 deletions src/blocking/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl Response {
/// StatusCode::PAYLOAD_TOO_LARGE => {
/// println!("Request payload is too large!");
/// }
/// s => println!("Received response status: {:?}", s),
/// s => println!("Received response status: {s:?}"),
/// };
/// # Ok(())
/// # }
Expand Down Expand Up @@ -252,7 +252,7 @@ impl Response {
/// # fn run() -> Result<(), Box<dyn std::error::Error>> {
/// let bytes = reqwest::blocking::get("http://httpbin.org/ip")?.bytes()?;
///
/// println!("bytes: {:?}", bytes);
/// println!("bytes: {bytes:?}");
/// # Ok(())
/// # }
/// ```
Expand Down
2 changes: 1 addition & 1 deletion src/blocking/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ where
enter();

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

Expand Down
Loading

0 comments on commit 2d6eb24

Please sign in to comment.