Skip to content

Commit 64a752f

Browse files
committed
Use named format arguments
1 parent 3b61514 commit 64a752f

File tree

23 files changed

+181
-129
lines changed

23 files changed

+181
-129
lines changed

crates/backend-embedded/src/storage.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,16 @@ pub fn provision_database(config: &DatabaseConfig) -> anyhow::Result<Gatekeeper>
2828
migrate_schema,
2929
} = config;
3030

31-
log::info!("Provisioning SQLite database: {}", connection.storage,);
31+
log::info!(
32+
"Provisioning SQLite database: {storage}",
33+
storage = connection.storage,
34+
);
3235

3336
// The maximum size of the pool defines the maximum number of
3437
// allowed readers while writers require exclusive access.
3538
log::info!(
36-
"Creating connection pool of max. size {}",
37-
connection.pool.max_size
39+
"Creating connection pool of max. size {max_size}",
40+
max_size = connection.pool.max_size
3841
);
3942
let connection_pool = create_connection_pool(&connection.storage, connection.pool.max_size)?;
4043

crates/client/src/models/collection/task/webapi.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async fn fetch_all_kinds<E: ClientEnvironment>(env: &E) -> anyhow::Result<Vec<St
4949
let response = request.send().await?;
5050
let response_body = receive_response_body(response).await?;
5151
let kinds = serde_json::from_slice::<Vec<String>>(&response_body)?;
52-
log::debug!("Fetched {} kind(s)", kinds.len(),);
52+
log::debug!("Fetched {num_kinds} kind(s)", num_kinds = kinds.len());
5353
Ok(kinds)
5454
}
5555

@@ -75,7 +75,10 @@ async fn fetch_filtered_entities<E: ClientEnvironment>(
7575
return Err(err);
7676
}
7777
let entities: Vec<_> = entities.into_iter().map(Result::unwrap).collect();
78-
log::debug!("Fetched {} filtered entities(s)", entities.len());
78+
log::debug!(
79+
"Fetched {num_entities} filtered entities(s)",
80+
num_entities = entities.len()
81+
);
7982
Ok(entities)
8083
}
8184

@@ -101,8 +104,9 @@ async fn update_entity<E: ClientEnvironment>(
101104
modified_collection: impl Into<aoide_core_json::collection::Collection>,
102105
) -> anyhow::Result<CollectionEntity> {
103106
let url = env.join_api_url(&format!(
104-
"c/{}?rev={}",
105-
entity_header.uid, entity_header.rev
107+
"c/{uid}?rev={rev}",
108+
uid = entity_header.uid,
109+
rev = entity_header.rev,
106110
))?;
107111
let body = serde_json::to_vec(&modified_collection.into())?;
108112
let request = env.client().put(url).body(body);

crates/core-json/src/tag/tests.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn deserialize_plain_tag_score_integer_zero() {
4747
fn deserialize_plain_tag_label_score() {
4848
let label = _core::Label::from_unchecked("label");
4949
let score = _core::Score::new_unchecked(0.5);
50-
let json = format!("[\"{label}\",{}]", score.value());
50+
let json = format!("[\"{label}\",{score_value}]", score_value = score.value());
5151
let tag: PlainTag = serde_json::from_str(&json).unwrap();
5252
assert_eq!(PlainTag::LabelScore(label.into(), score.into()), tag);
5353
assert_eq!(json, serde_json::to_string(&tag).unwrap());
@@ -60,7 +60,10 @@ fn deserialize_plain_tag_label_score_integer_zero() {
6060
score: _core::Score::new_unchecked(0.0),
6161
};
6262
// Ensure to parse score from literal 0, not 0.0!
63-
let json = format!("[\"{}\",0]", expected_tag.label.as_ref().unwrap());
63+
let json = format!(
64+
"[\"{label}\",0]",
65+
label = expected_tag.label.as_ref().unwrap()
66+
);
6467
let parsed_tag: PlainTag = serde_json::from_str(&json).unwrap();
6568
assert_eq!(json, serde_json::to_string(&parsed_tag).unwrap());
6669
assert_eq!(expected_tag, parsed_tag.into());
@@ -73,7 +76,10 @@ fn deserialize_plain_tag_label_score_integer_one() {
7376
score: _core::Score::new_unchecked(1.0),
7477
};
7578
// Ensure to parse score from literal 1, not 1.0!
76-
let json = format!("[\"{}\",1]", expected_tag.label.as_ref().unwrap());
79+
let json = format!(
80+
"[\"{label}\",1]",
81+
label = expected_tag.label.as_ref().unwrap()
82+
);
7783
let parsed_tag: PlainTag = serde_json::from_str(&json).unwrap();
7884
assert_eq!(json, serde_json::to_string(&parsed_tag).unwrap());
7985
assert_eq!(expected_tag, parsed_tag.into());

crates/core/src/tag/score/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ fn validate() {
2020

2121
#[test]
2222
fn display() {
23-
assert_eq!("0.0%", format!("{}", Score::MIN));
24-
assert_eq!("100.0%", format!("{}", Score::MAX));
25-
assert_eq!("90.1%", format!("{}", Score(0.901_234_5)));
26-
assert_eq!("90.2%", format!("{}", Score(0.901_5)));
23+
assert_eq!("0.0%", Score::MIN.to_string());
24+
assert_eq!("100.0%", Score::MAX.to_string());
25+
assert_eq!("90.1%", Score(0.901_234_5).to_string());
26+
assert_eq!("90.2%", Score(0.901_5).to_string());
2727
}

crates/core/src/track/actor/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ impl ActorNamesSummarySplitter {
279279
protected_names: impl IntoIterator<Item = &'a str>,
280280
) -> Self {
281281
let name_separator_pattern = format!(
282-
r"({})",
283-
name_separators
282+
r"({pattern})",
283+
pattern = name_separators
284284
.into_iter()
285285
.map(|separator| regex::escape(separator).replace(' ', r"\s+"))
286286
.collect::<Vec<_>>()

crates/core/src/util/color/mod.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ impl RgbColor {
102102
impl fmt::Display for RgbColor {
103103
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
104104
// "#RRGGBB"
105-
write!(f, "{}{:06X}", Self::STRING_PREFIX, self.code())
105+
write!(
106+
f,
107+
"{prefix}{code:06X}",
108+
prefix = Self::STRING_PREFIX,
109+
code = self.code()
110+
)
106111
}
107112
}
108113

@@ -118,13 +123,13 @@ impl fmt::Display for ParseError {
118123
match self {
119124
Self::InputLen => write!(
120125
f,
121-
"Invalid input length: expected = {}",
122-
RgbColor::STRING_LEN
126+
"Invalid input length: expected = {expected}",
127+
expected = RgbColor::STRING_LEN,
123128
),
124129
Self::InputPrefix => write!(
125130
f,
126-
"Invalid input prefix: expected = {}",
127-
RgbColor::STRING_PREFIX
131+
"Invalid input prefix: expected = {expected}",
132+
expected = RgbColor::STRING_PREFIX,
128133
),
129134
Self::ParseIntError(err) => f.write_str(&err.to_string()),
130135
}

crates/core/src/util/url/fs/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ pub fn url_from_path(path: &Path) -> Result<Url, ()> {
1717
} else {
1818
debug_assert!(
1919
false,
20-
"file type of path {} cannot be determined",
21-
path.display()
20+
"file type of path {path} cannot be determined",
21+
path = path.display()
2222
);
2323
Err(())
2424
}

crates/desktop-app/src/collection/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,13 @@ impl Default for RestoreOrCreateState {
111111
}
112112

113113
fn parse_music_dir_path(path: &Path) -> anyhow::Result<(BaseUrl, PathBuf)> {
114-
let root_url = BaseUrl::try_autocomplete_from(
115-
Url::from_directory_path(path)
116-
.map_err(|()| anyhow::anyhow!("unrecognized music directory: {}", path.display()))?,
117-
)?;
114+
let root_url =
115+
BaseUrl::try_autocomplete_from(Url::from_directory_path(path).map_err(|()| {
116+
anyhow::anyhow!(
117+
"unrecognized music directory: {path}",
118+
path = path.display()
119+
)
120+
})?)?;
118121
let root_path = root_url
119122
.to_file_path()
120123
.map_err(|()| anyhow::anyhow!("invalid music directory"))?;

crates/desktop-app/src/settings/mod.rs

+27-17
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,20 @@ pub struct State {
4646

4747
impl State {
4848
pub fn restore_from_parent_dir(parent_dir: &Path) -> anyhow::Result<Self> {
49-
log::info!("Loading saved settings from: {}", parent_dir.display());
49+
log::info!(
50+
"Loading saved settings from: {parent_dir}",
51+
parent_dir = parent_dir.display()
52+
);
5053
let mut settings = Self::load(parent_dir)
5154
.map_err(|err| {
52-
log::warn!("Failed to load saved settings: {}", err);
55+
log::warn!("Failed to load saved settings: {err}");
5356
})
5457
.unwrap_or_default();
5558
if settings.database_url.is_none() {
5659
let database_file_path = default_database_file_path(parent_dir.to_path_buf());
5760
log::info!(
58-
"Using default SQLite database: {}",
59-
database_file_path.display()
61+
"Using default SQLite database: {database_file_path}",
62+
database_file_path = database_file_path.display()
6063
);
6164
settings.database_url = Url::from_file_path(&database_file_path).ok();
6265
}
@@ -66,7 +69,10 @@ impl State {
6669

6770
pub fn load(parent_dir: &Path) -> anyhow::Result<State> {
6871
let file_path = new_settings_file_path(parent_dir.to_path_buf());
69-
log::info!("Loading settings from file: {}", file_path.display());
72+
log::info!(
73+
"Loading settings from file: {file_path}",
74+
file_path = file_path.display()
75+
);
7076
match fs::read(&file_path) {
7177
Ok(bytes) => ron::de::from_bytes(&bytes).map_err(Into::into),
7278
Err(err) if err.kind() == std::io::ErrorKind::NotFound => Ok(Default::default()),
@@ -76,7 +82,10 @@ impl State {
7682

7783
pub fn save(&self, parent_dir: &Path) -> anyhow::Result<()> {
7884
let file_path = new_settings_file_path(parent_dir.to_path_buf());
79-
log::info!("Saving current settings into file: {}", file_path.display());
85+
log::info!(
86+
"Saving current settings into file: {file_path}",
87+
file_path = file_path.display()
88+
);
8089
let mut bytes = vec![];
8190
ron::ser::to_writer_pretty(&mut bytes, self, Default::default())?;
8291
if let Some(parent_path) = file_path.parent() {
@@ -122,7 +131,7 @@ impl State {
122131
.ok_or_else(|| anyhow::anyhow!("missing database URL"))?;
123132
let file_path = url
124133
.to_file_path()
125-
.map_err(|()| anyhow::anyhow!("unsupported database URL: {}", url))?;
134+
.map_err(|()| anyhow::anyhow!("unsupported database URL: {url}"))?;
126135
let config = DatabaseConfig {
127136
connection: aoide_storage_sqlite::connection::Config {
128137
storage: aoide_storage_sqlite::connection::Storage::File { path: file_path },
@@ -139,19 +148,20 @@ impl State {
139148
Ok(config)
140149
}
141150

142-
pub fn update_music_dir(&mut self, new_music_dir: Option<&DirPath<'_>>) -> bool {
143-
if self.music_dir.as_ref() == new_music_dir {
144-
log::debug!("Unchanged music directory: {new_music_dir:?}");
151+
pub fn update_music_dir(&mut self, music_dir: Option<&DirPath<'_>>) -> bool {
152+
if self.music_dir.as_ref() == music_dir {
153+
log::debug!("Unchanged music directory: {music_dir:?}");
145154
return false;
146155
}
147-
if let Some(new_music_dir) = new_music_dir {
148-
log::info!("Updating music directory: {}", new_music_dir.display());
156+
if let Some(music_dir) = music_dir {
157+
log::info!(
158+
"Updating music directory: {music_dir}",
159+
music_dir = music_dir.display()
160+
);
149161
} else {
150162
log::info!("Resetting music directory");
151163
}
152-
self.music_dir = new_music_dir
153-
.map(ToOwned::to_owned)
154-
.map(DirPath::into_owned);
164+
self.music_dir = music_dir.map(ToOwned::to_owned).map(DirPath::into_owned);
155165
true
156166
}
157167
}
@@ -199,8 +209,8 @@ impl ObservableState {
199209
}
200210

201211
#[allow(clippy::must_use_candidate)]
202-
pub fn update_music_dir(&self, new_music_dir: Option<&DirPath<'_>>) -> bool {
203-
self.0.modify(|state| state.update_music_dir(new_music_dir))
212+
pub fn update_music_dir(&self, music_dir: Option<&DirPath<'_>>) -> bool {
213+
self.0.modify(|state| state.update_music_dir(music_dir))
204214
}
205215
}
206216

crates/media-file/src/fs/digest/mod.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ pub fn hash_directories<
148148
directory_visitor: &mut HashDirectoryVisitor<D, E, NewDigestFn, DigestFinishedFn>,
149149
report_progress_fn: &mut ReportProgressFn,
150150
) -> Result<Outcome> {
151-
log::info!("Digesting all directories in '{}'", root_path.display());
151+
log::info!(
152+
"Digesting all directories in '{root_path}'",
153+
root_path = root_path.display()
154+
);
152155
visit_directories(
153156
&mut (),
154157
root_path,
@@ -163,10 +166,10 @@ pub fn hash_directories<
163166
let elapsed = progress_event.elapsed_since_started();
164167
let outcome = progress_event.finalize();
165168
log::info!(
166-
"Digesting {} directories in '{}' took {} s",
167-
outcome.progress.directories.finished,
168-
root_path.display(),
169-
elapsed.as_secs_f64(),
169+
"Digesting {finished} directories in '{root_path}' took {elapsed} s",
170+
finished = outcome.progress.directories.finished,
171+
root_path = root_path.display(),
172+
elapsed = elapsed.as_secs_f64(),
170173
);
171174
outcome
172175
})

crates/media-file/src/fs/visit/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,10 @@ pub fn visit_directories<
298298
let (ancestor_path, ancestor_visitor) =
299299
ancestor_visitors.pop().expect("last ancestor visitor");
300300
let ancestor_finished = ancestor_visitor.finish();
301-
log::debug!("Finalized parent directory: {}", ancestor_path.display());
301+
log::debug!(
302+
"Finalized parent directory: {ancestor_path}",
303+
ancestor_path = ancestor_path.display()
304+
);
302305
#[allow(clippy::blocks_in_conditions)] // TODO
303306
match directory_visitor
304307
.after_ancestor_finished(&ancestor_path, ancestor_finished)

crates/media-file/src/io/import/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,9 @@ impl Importer {
490490
let titles = titles.canonicalize_into();
491491
if titles.len() < titles_len {
492492
self.issues.add_message(format!(
493-
"Discarded {} duplicate {} titles",
494-
titles_len - titles.len(),
495-
scope.message_str(),
493+
"Discarded {num_duplicates} duplicate {scope} titles",
494+
num_duplicates = titles_len - titles.len(),
495+
scope = scope.message_str(),
496496
));
497497
}
498498
titles
@@ -508,9 +508,9 @@ impl Importer {
508508
let actors = actors.canonicalize_into();
509509
if actors.len() < actors_len {
510510
self.issues.add_message(format!(
511-
"Discarded {} duplicate {} actors",
512-
actors_len - actors.len(),
513-
scope.message_str(),
511+
"Discarded {duplicate_count} duplicate {scope} actors",
512+
duplicate_count = actors_len - actors.len(),
513+
scope = scope.message_str(),
514514
));
515515
}
516516
actors
@@ -624,8 +624,8 @@ impl Importer {
624624
let count = plain_tags.len();
625625
if count < total_import_count {
626626
self.issues.add_message(format!(
627-
"Discarded {} duplicate tag labels for facet '{facet_id}'",
628-
total_import_count - count,
627+
"Discarded {duplicate_count} duplicate tag labels for facet '{facet_id}'",
628+
duplicate_count = total_import_count - count,
629629
));
630630
}
631631
tags_map.update_faceted_plain_tags_by_label_ordering(facet_id, plain_tags);

crates/repo-sqlite/src/repo/media/source/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ impl<'db> CollectionRepo for crate::prelude::Connection<'db> {
110110
.set((
111111
media_source::row_updated_ms.eq(updated_at.timestamp_millis()),
112112
media_source::content_link_path.eq(diesel::dsl::sql(&format!(
113-
"'{}' || substr(content_link_path,{})",
114-
escape_single_quotes(new_content_path_prefix.as_ref()),
115-
old_content_path_prefix.len() + 1
113+
"'{escaped}' || substr(content_link_path,{len})",
114+
escaped = escape_single_quotes(new_content_path_prefix.as_ref()),
115+
len = old_content_path_prefix.len() + 1
116116
))),
117117
))
118118
.execute(self.as_mut())

crates/repo-sqlite/src/util/mod.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,23 @@ pub(crate) fn escape_single_quotes(arg: &str) -> String {
7676
}
7777

7878
pub(crate) fn escape_like_starts_with(arg: &str) -> String {
79-
format!("{}{LIKE_WILDCARD_CHARACTER}", escape_like_matches(arg))
79+
format!(
80+
"{escaped}{LIKE_WILDCARD_CHARACTER}",
81+
escaped = escape_like_matches(arg)
82+
)
8083
}
8184

8285
pub(crate) fn escape_like_ends_with(arg: &str) -> String {
83-
format!("{LIKE_WILDCARD_CHARACTER}{}", escape_like_matches(arg))
86+
format!(
87+
"{LIKE_WILDCARD_CHARACTER}{escaped}",
88+
escaped = escape_like_matches(arg)
89+
)
8490
}
8591

8692
pub(crate) fn escape_like_contains(arg: &str) -> String {
8793
format!(
88-
"{LIKE_WILDCARD_CHARACTER}{}{LIKE_WILDCARD_CHARACTER}",
89-
escape_like_matches(arg),
94+
"{LIKE_WILDCARD_CHARACTER}{escaped}{LIKE_WILDCARD_CHARACTER}",
95+
escaped = escape_like_matches(arg),
9096
)
9197
}
9298

0 commit comments

Comments
 (0)