Skip to content

Commit bab9afa

Browse files
committed
Address clippy reported issues
In recent versions of Rust variables can be referenced directory in format! strings. Do just that, instead of passing them in as "extra" arguments to make clippy happy.
1 parent a95223d commit bab9afa

File tree

5 files changed

+17
-25
lines changed

5 files changed

+17
-25
lines changed

src/index.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn parse_port(url: &str) -> Result<u16> {
4242
.nth(2)
4343
.ok_or_else(|| anyhow!("provided URL {} has unexpected format", url))?;
4444
let addr =
45-
SocketAddr::from_str(addr).with_context(|| format!("failed to parse address {}", addr))?;
45+
SocketAddr::from_str(addr).with_context(|| format!("failed to parse address {addr}"))?;
4646
Ok(addr.port())
4747
}
4848

@@ -299,11 +299,8 @@ impl Index {
299299
match result {
300300
Ok(file) => {
301301
let mut config = from_reader::<_, Config>(&file).context("failed to parse config.json")?;
302-
let dl = format!(
303-
"http://{}/api/v1/crates/{{crate}}/{{version}}/download",
304-
addr
305-
);
306-
let api = format!("http://{}", addr);
302+
let dl = format!("http://{addr}/api/v1/crates/{{crate}}/{{version}}/download");
303+
let api = format!("http://{addr}");
307304
if config.dl != dl || config.api.as_ref() != Some(&api) {
308305
config.dl = dl;
309306
config.api = Some(api);
@@ -326,11 +323,8 @@ impl Index {
326323
Err(err) if err.kind() == ErrorKind::NotFound => {
327324
let file = File::create(&path).context("failed to create config.json")?;
328325
let config = Config {
329-
dl: format!(
330-
"http://{}/api/v1/crates/{{crate}}/{{version}}/download",
331-
addr
332-
),
333-
api: Some(format!("http://{}", addr)),
326+
dl: format!("http://{addr}/api/v1/crates/{{crate}}/{{version}}/download"),
327+
api: Some(format!("http://{addr}")),
334328
};
335329
to_writer_pretty(&file, &config).context("failed to write config.json")?;
336330

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn run() -> Result<()> {
6464
fn main() {
6565
let exit_code = run()
6666
.map(|_| 0)
67-
.map_err(|e| eprintln!("{:?}", e))
67+
.map_err(|e| eprintln!("{e:?}"))
6868
.unwrap_or(1);
6969

7070
// We exit the process the hard way next, so make sure to flush

src/publish.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2020-2023 The cargo-http-registry Developers
1+
// Copyright (C) 2020-2025 The cargo-http-registry Developers
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

44
use std::collections::BTreeMap;
@@ -176,7 +176,7 @@ impl From<(MetaData, &[u8])> for Entry {
176176

177177
/// Craft the file name for a crate named `name` in version `version`.
178178
pub fn crate_file_name(name: &str, version: &str) -> String {
179-
format!("{}-{}.crate", name, version)
179+
format!("{name}-{version}.crate")
180180
}
181181

182182
/// Extract and parse a `u32` value from a `Bytes` object.
@@ -305,15 +305,15 @@ pub fn publish_crate(mut body: Bytes, index: &mut Index) -> Result<()> {
305305
crate_meta_path.display(),
306306
)
307307
})?;
308-
index
309-
.add(&crate_relative_path)
310-
.with_context(|| format!(
308+
index.add(&crate_relative_path).with_context(|| {
309+
format!(
311310
"failed to add {} to git repository (full path: {})",
312311
crate_relative_path.display(),
313312
crate_path.display(),
314-
))?;
313+
)
314+
})?;
315315
index
316-
.commit(&format!("Add {} in version {}", crate_name, crate_vers))
316+
.commit(&format!("Add {crate_name} in version {crate_vers}"))
317317
.context("failed to commit changes to index")?;
318318

319319
if !body.is_empty() {

src/serve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2021-2023 The cargo-http-registry Developers
1+
// Copyright (C) 2021-2025 The cargo-http-registry Developers
22
// SPDX-License-Identifier: GPL-3.0-or-later
33

44
use std::future::Future;
@@ -148,7 +148,7 @@ pub fn serve(root: &Path, addr: SocketAddr) -> Result<(impl Future<Output = ()>,
148148
// happen outside of a tokio runtime. Boy.
149149
let result = warp::serve(routes)
150150
.try_bind_ephemeral(addr)
151-
.with_context(|| format!("failed to bind to {}", addr));
151+
.with_context(|| format!("failed to bind to {addr}"));
152152

153153
match result {
154154
Ok(result) => break result,

tests/end-to-end.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,13 @@ token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
9999
Locator::Socket(addr) => {
100100
format!(
101101
r#"
102-
[registries.{registry}]
102+
[registries.{REGISTRY}]
103103
index = "http://{addr}/git"
104104
token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
105105
106106
[net]
107107
git-fetch-with-cli = true
108108
"#,
109-
registry = REGISTRY,
110-
addr = addr,
111109
)
112110
},
113111
};
@@ -317,7 +315,7 @@ async fn test_publish_and_consume(registry_locator: Locator) {
317315
cargo_init(&home, ["--bin", my_bin.to_str().unwrap()])
318316
.await
319317
.unwrap();
320-
let data = format!(r#"my-lib = {{version = "*", registry = "{}"}}"#, REGISTRY);
318+
let data = format!(r#"my-lib = {{version = "*", registry = "{REGISTRY}"}}"#);
321319
append(&cargo_toml, data).unwrap();
322320

323321
let data = "#[allow(unused_imports)] use my_lib::foo;\n";

0 commit comments

Comments
 (0)