diff --git a/axum-extra/src/routing/mod.rs b/axum-extra/src/routing/mod.rs index 6d52c284..588618a6 100644 --- a/axum-extra/src/routing/mod.rs +++ b/axum-extra/src/routing/mod.rs @@ -313,7 +313,7 @@ where if let Some(path_without_trailing_slash) = path.strip_suffix('/') { router.route(path_without_trailing_slash, any(redirect_handler)) } else { - router.route(&format!("{}/", path), any(redirect_handler)) + router.route(&format!("{path}/"), any(redirect_handler)) } } diff --git a/axum-extra/src/routing/resource.rs b/axum-extra/src/routing/resource.rs index ca1035f5..11f49d22 100644 --- a/axum-extra/src/routing/resource.rs +++ b/axum-extra/src/routing/resource.rs @@ -157,10 +157,10 @@ mod tests { .index(|| async { "users#index" }) .create(|| async { "users#create" }) .new(|| async { "users#new" }) - .show(|Path(id): Path<u64>| async move { format!("users#show id={}", id) }) - .edit(|Path(id): Path<u64>| async move { format!("users#edit id={}", id) }) - .update(|Path(id): Path<u64>| async move { format!("users#update id={}", id) }) - .destroy(|Path(id): Path<u64>| async move { format!("users#destroy id={}", id) }); + .show(|Path(id): Path<u64>| async move { format!("users#show id={id}") }) + .edit(|Path(id): Path<u64>| async move { format!("users#edit id={id}") }) + .update(|Path(id): Path<u64>| async move { format!("users#update id={id}") }) + .destroy(|Path(id): Path<u64>| async move { format!("users#destroy id={id}") }); let mut app = Router::new().merge(users); diff --git a/axum-macros/src/attr_parsing.rs b/axum-macros/src/attr_parsing.rs index bfb5d52f..a6eff772 100644 --- a/axum-macros/src/attr_parsing.rs +++ b/axum-macros/src/attr_parsing.rs @@ -20,7 +20,7 @@ where if out.is_some() { let kw_name = std::any::type_name::<K>().split("::").last().unwrap(); - let msg = format!("`{}` specified more than once", kw_name); + let msg = format!("`{kw_name}` specified more than once"); return Err(syn::Error::new_spanned(kw, msg)); } @@ -43,7 +43,7 @@ where if out.is_some() { let kw_name = std::any::type_name::<K>().split("::").last().unwrap(); - let msg = format!("`{}` specified more than once", kw_name); + let msg = format!("`{kw_name}` specified more than once"); return Err(syn::Error::new_spanned(kw, msg)); } @@ -74,7 +74,7 @@ where if let Some((kw, inner)) = b { if a.is_some() { let kw_name = std::any::type_name::<K>().split("::").last().unwrap(); - let msg = format!("`{}` specified more than once", kw_name); + let msg = format!("`{kw_name}` specified more than once"); return Err(syn::Error::new_spanned(kw, msg)); } *a = Some((kw, inner)); @@ -89,7 +89,7 @@ where if let Some(kw) = b { if a.is_some() { let kw_name = std::any::type_name::<K>().split("::").last().unwrap(); - let msg = format!("`{}` specified more than once", kw_name); + let msg = format!("`{kw_name}` specified more than once"); return Err(syn::Error::new_spanned(kw, msg)); } *a = Some(kw); diff --git a/axum-macros/src/debug_handler.rs b/axum-macros/src/debug_handler.rs index ea685e09..9934e277 100644 --- a/axum-macros/src/debug_handler.rs +++ b/axum-macros/src/debug_handler.rs @@ -111,9 +111,8 @@ fn check_extractor_count(item_fn: &ItemFn) -> Option<TokenStream> { None } else { let error_message = format!( - "Handlers cannot take more than {} arguments. \ + "Handlers cannot take more than {max_extractors} arguments. \ Use `(a, b): (ExtractorA, ExtractorA)` to further nest extractors", - max_extractors, ); let error = syn::Error::new_spanned(&item_fn.sig.inputs, error_message).to_compile_error(); Some(error) diff --git a/axum-macros/src/lib.rs b/axum-macros/src/lib.rs index 98380d0b..78575390 100644 --- a/axum-macros/src/lib.rs +++ b/axum-macros/src/lib.rs @@ -665,7 +665,7 @@ where Ok(tokens) => { let tokens = (quote! { #tokens }).into(); if std::env::var_os("AXUM_MACROS_DEBUG").is_some() { - eprintln!("{}", tokens); + eprintln!("{tokens}"); } tokens } @@ -722,7 +722,7 @@ fn run_ui_tests(directory: &str) { path = path_without_prefix.to_owned(); } - if !path.contains(&format!("/{}/", directory)) { + if !path.contains(&format!("/{directory}/")) { return; } @@ -734,8 +734,8 @@ fn run_ui_tests(directory: &str) { panic!() } } else { - t.compile_fail(format!("tests/{}/fail/*.rs", directory)); - t.pass(format!("tests/{}/pass/*.rs", directory)); + t.compile_fail(format!("tests/{directory}/fail/*.rs")); + t.pass(format!("tests/{directory}/pass/*.rs")); } } diff --git a/axum-macros/src/typed_path.rs b/axum-macros/src/typed_path.rs index 6a50886f..61db3eb9 100644 --- a/axum-macros/src/typed_path.rs +++ b/axum-macros/src/typed_path.rs @@ -267,9 +267,9 @@ fn expand_unnamed_fields( fn simple_pluralize(count: usize, word: &str) -> String { if count == 1 { - format!("{} {}", count, word) + format!("{count} {word}") } else { - format!("{} {}s", count, word) + format!("{count} {word}s") } } @@ -354,7 +354,7 @@ fn format_str_from_path(segments: &[Segment]) -> String { segments .iter() .map(|segment| match segment { - Segment::Capture(capture, _) => format!("{{{}}}", capture), + Segment::Capture(capture, _) => format!("{{{capture}}}"), Segment::Static(segment) => segment.to_owned(), }) .collect::<Vec<_>>() diff --git a/axum/benches/benches.rs b/axum/benches/benches.rs index 3a7dd998..50a7417b 100644 --- a/axum/benches/benches.rs +++ b/axum/benches/benches.rs @@ -26,7 +26,7 @@ fn main() { for a in 0..10 { for b in 0..10 { for c in 0..10 { - app = app.route(&format!("/foo-{}/bar-{}/baz-{}", a, b, c), get(|| async {})); + app = app.route(&format!("/foo-{a}/bar-{b}/baz-{c}"), get(|| async {})); } } } @@ -181,7 +181,7 @@ impl BenchmarkBuilder { for (key, value) in self.headers.into_iter().flatten() { cmd.arg("--header"); - cmd.arg(format!("{}: {}", key, value)); + cmd.arg(format!("{key}: {value}")); } if let Some(body) = self.body { @@ -196,7 +196,7 @@ impl BenchmarkBuilder { let stdout = std::io::BufReader::new(stdout); for line in stdout.lines() { let line = line.unwrap(); - println!(" {}", line); + println!(" {line}"); } let status = child.wait().unwrap(); diff --git a/axum/src/extract/connect_info.rs b/axum/src/extract/connect_info.rs index 92f418c8..2ab24863 100644 --- a/axum/src/extract/connect_info.rs +++ b/axum/src/extract/connect_info.rs @@ -151,7 +151,7 @@ mod tests { #[crate::test] async fn socket_addr() { async fn handler(ConnectInfo(addr): ConnectInfo<SocketAddr>) -> String { - format!("{}", addr) + format!("{addr}") } let listener = TcpListener::bind("127.0.0.1:0").unwrap(); @@ -170,7 +170,7 @@ mod tests { let client = reqwest::Client::new(); - let res = client.get(format!("http://{}", addr)).send().await.unwrap(); + let res = client.get(format!("http://{addr}")).send().await.unwrap(); let body = res.text().await.unwrap(); assert!(body.starts_with("127.0.0.1:")); } @@ -210,7 +210,7 @@ mod tests { let client = reqwest::Client::new(); - let res = client.get(format!("http://{}", addr)).send().await.unwrap(); + let res = client.get(format!("http://{addr}")).send().await.unwrap(); let body = res.text().await.unwrap(); assert_eq!(body, "it worked!"); } diff --git a/axum/src/extract/path/mod.rs b/axum/src/extract/path/mod.rs index de547337..44c9bc04 100644 --- a/axum/src/extract/path/mod.rs +++ b/axum/src/extract/path/mod.rs @@ -334,12 +334,11 @@ impl fmt::Display for ErrorKind { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { ErrorKind::Message(error) => error.fmt(f), - ErrorKind::InvalidUtf8InPathParam { key } => write!(f, "Invalid UTF-8 in `{}`", key), + ErrorKind::InvalidUtf8InPathParam { key } => write!(f, "Invalid UTF-8 in `{key}`"), ErrorKind::WrongNumberOfParameters { got, expected } => { write!( f, - "Wrong number of path arguments for `Path`. Expected {} but got {}", - expected, got + "Wrong number of path arguments for `Path`. Expected {expected} but got {got}" )?; if *expected == 1 { @@ -348,28 +347,26 @@ impl fmt::Display for ErrorKind { Ok(()) } - ErrorKind::UnsupportedType { name } => write!(f, "Unsupported type `{}`", name), + ErrorKind::UnsupportedType { name } => write!(f, "Unsupported type `{name}`"), ErrorKind::ParseErrorAtKey { key, value, expected_type, } => write!( f, - "Cannot parse `{}` with value `{:?}` to a `{}`", - key, value, expected_type + "Cannot parse `{key}` with value `{value:?}` to a `{expected_type}`" ), ErrorKind::ParseError { value, expected_type, - } => write!(f, "Cannot parse `{:?}` to a `{}`", value, expected_type), + } => write!(f, "Cannot parse `{value:?}` to a `{expected_type}`"), ErrorKind::ParseErrorAtIndex { index, value, expected_type, } => write!( f, - "Cannot parse value at index {} with value `{:?}` to a `{}`", - index, value, expected_type + "Cannot parse value at index {index} with value `{value:?}` to a `{expected_type}`" ), } } diff --git a/axum/src/handler/mod.rs b/axum/src/handler/mod.rs index c0d22b02..338eea62 100644 --- a/axum/src/handler/mod.rs +++ b/axum/src/handler/mod.rs @@ -355,7 +355,7 @@ mod tests { #[crate::test] async fn handler_into_service() { async fn handle(body: String) -> impl IntoResponse { - format!("you said: {}", body) + format!("you said: {body}") } let client = TestClient::new(handle.into_service()); diff --git a/axum/src/json.rs b/axum/src/json.rs index 58c04254..27325e86 100644 --- a/axum/src/json.rs +++ b/axum/src/json.rs @@ -262,7 +262,7 @@ mod tests { #[crate::test] async fn json_content_types() { async fn valid_json_content_type(content_type: &str) -> bool { - println!("testing {:?}", content_type); + println!("testing {content_type:?}"); let app = Router::new().route("/", post(|Json(_): Json<Value>| async {})); diff --git a/axum/src/routing/strip_prefix.rs b/axum/src/routing/strip_prefix.rs index ec0e2325..521b774e 100644 --- a/axum/src/routing/strip_prefix.rs +++ b/axum/src/routing/strip_prefix.rs @@ -107,9 +107,9 @@ fn strip_prefix(uri: &Uri, prefix: &str) -> Option<Uri> { let new_path_and_query = match (after_prefix.starts_with('/'), path_and_query.query()) { (true, None) => after_prefix.parse().unwrap(), - (true, Some(query)) => format!("{}?{}", after_prefix, query).parse().unwrap(), - (false, None) => format!("/{}", after_prefix).parse().unwrap(), - (false, Some(query)) => format!("/{}?{}", after_prefix, query).parse().unwrap(), + (true, Some(query)) => format!("{after_prefix}?{query}").parse().unwrap(), + (false, None) => format!("/{after_prefix}").parse().unwrap(), + (false, Some(query)) => format!("/{after_prefix}?{query}").parse().unwrap(), }; let mut parts = uri.clone().into_parts(); diff --git a/axum/src/routing/tests/merge.rs b/axum/src/routing/tests/merge.rs index 0ec8576c..ad3cfb0c 100644 --- a/axum/src/routing/tests/merge.rs +++ b/axum/src/routing/tests/merge.rs @@ -63,8 +63,8 @@ async fn multiple_ors_balanced_differently() { let client = TestClient::new(app); for n in ["one", "two", "three", "four"].iter() { - println!("running: {} / {}", name, n); - let res = client.get(&format!("/{}", n)).send().await; + println!("running: {name} / {n}"); + let res = client.get(&format!("/{n}")).send().await; assert_eq!(res.status(), StatusCode::OK); assert_eq!(res.text().await, *n); } @@ -180,7 +180,7 @@ async fn many_ors() { let client = TestClient::new(app); for n in 1..=7 { - let res = client.get(&format!("/r{}", n)).send().await; + let res = client.get(&format!("/r{n}")).send().await; assert_eq!(res.status(), StatusCode::OK); } diff --git a/axum/src/routing/tests/mod.rs b/axum/src/routing/tests/mod.rs index 272430f1..300e55b2 100644 --- a/axum/src/routing/tests/mod.rs +++ b/axum/src/routing/tests/mod.rs @@ -385,7 +385,7 @@ async fn static_and_dynamic_paths() { let app = Router::new() .route( "/:key", - get(|Path(key): Path<String>| async move { format!("dynamic: {}", key) }), + get(|Path(key): Path<String>| async move { format!("dynamic: {key}") }), ) .route("/foo", get(|| async { "static" })); @@ -618,7 +618,7 @@ async fn body_limited_by_default() { let client = TestClient::new(app); for uri in ["/bytes", "/string", "/json"] { - println!("calling {}", uri); + println!("calling {uri}"); let stream = futures_util::stream::repeat("a".repeat(1000)).map(Ok::<_, hyper::Error>); let body = Body::wrap_stream(stream); diff --git a/axum/src/routing/tests/nest.rs b/axum/src/routing/tests/nest.rs index 344789c2..0df8be6d 100644 --- a/axum/src/routing/tests/nest.rs +++ b/axum/src/routing/tests/nest.rs @@ -207,7 +207,7 @@ async fn nest_static_file_server() { get_service(ServeDir::new(".")).handle_error(|error| async move { ( StatusCode::INTERNAL_SERVER_ERROR, - format!("Unhandled internal error: {}", error), + format!("Unhandled internal error: {error}"), ) }), ); @@ -323,7 +323,7 @@ async fn outer_middleware_still_see_whole_url() { async fn nest_at_capture() { let api_routes = Router::new().route( "/:b", - get(|Path((a, b)): Path<(String, String)>| async move { format!("a={} b={}", a, b) }), + get(|Path((a, b)): Path<(String, String)>| async move { format!("a={a} b={b}") }), ); let app = Router::new().nest("/:a", api_routes); diff --git a/axum/src/test_helpers/test_client.rs b/axum/src/test_helpers/test_client.rs index 45a72b6c..d1d73f6c 100644 --- a/axum/src/test_helpers/test_client.rs +++ b/axum/src/test_helpers/test_client.rs @@ -26,7 +26,7 @@ impl TestClient { { let listener = TcpListener::bind("127.0.0.1:0").expect("Could not bind ephemeral socket"); let addr = listener.local_addr().unwrap(); - println!("Listening on {}", addr); + println!("Listening on {addr}"); tokio::spawn(async move { let server = Server::from_tcp(listener).unwrap().serve(Shared::new(svc));