Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a88fc1

Browse files
authored
style: simplify string formatting (tauri-apps#10259)
* style: simplfiy string formatting * fix: file formatting in `core/`
1 parent 2b1ceb4 commit 1a88fc1

File tree

9 files changed

+20
-34
lines changed

9 files changed

+20
-34
lines changed

core/tauri-build/src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ fn copy_dir(from: &Path, to: &Path) -> Result<()> {
156156

157157
// Copies the framework under `{src_dir}/{framework}.framework` to `{dest_dir}/{framework}.framework`.
158158
fn copy_framework_from(src_dir: &Path, framework: &str, dest_dir: &Path) -> Result<bool> {
159-
let src_name = format!("{}.framework", framework);
159+
let src_name = format!("{framework}.framework");
160160
let src_path = src_dir.join(&src_name);
161161
if src_path.exists() {
162162
copy_dir(&src_path, &dest_dir.join(&src_name))?;
@@ -168,12 +168,8 @@ fn copy_framework_from(src_dir: &Path, framework: &str, dest_dir: &Path) -> Resu
168168

169169
// Copies the macOS application bundle frameworks to the target folder
170170
fn copy_frameworks(dest_dir: &Path, frameworks: &[String]) -> Result<()> {
171-
std::fs::create_dir_all(dest_dir).with_context(|| {
172-
format!(
173-
"Failed to create frameworks output directory at {:?}",
174-
dest_dir
175-
)
176-
})?;
171+
std::fs::create_dir_all(dest_dir)
172+
.with_context(|| format!("Failed to create frameworks output directory at {dest_dir:?}"))?;
177173
for framework in frameworks.iter() {
178174
if framework.ends_with(".framework") {
179175
let src_path = PathBuf::from(framework);
@@ -469,7 +465,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
469465
let mut android_package_prefix = String::new();
470466
for (i, w) in s.enumerate() {
471467
if i == last {
472-
println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={}", w);
468+
println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={w}");
473469
} else {
474470
android_package_prefix.push_str(w);
475471
android_package_prefix.push('_');

core/tauri-build/src/mobile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ dependencies {"
5555
app_build_gradle.push_str("\n}");
5656

5757
if let Some(version) = config.version.as_ref() {
58-
app_tauri_properties.push(format!("tauri.android.versionName={}", version));
58+
app_tauri_properties.push(format!("tauri.android.versionName={version}"));
5959
if let Some(version_code) = config.bundle.android.version_code.as_ref() {
60-
app_tauri_properties.push(format!("tauri.android.versionCode={}", version_code));
60+
app_tauri_properties.push(format!("tauri.android.versionCode={version_code}"));
6161
} else if let Ok(version) = Version::parse(version) {
6262
let mut version_code = version.major * 1000000 + version.minor * 1000 + version.patch;
6363

@@ -76,7 +76,7 @@ dependencies {"
7676
));
7777
}
7878

79-
app_tauri_properties.push(format!("tauri.android.versionCode={}", version_code));
79+
app_tauri_properties.push(format!("tauri.android.versionCode={version_code}"));
8080
}
8181
}
8282

core/tauri-codegen/src/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
183183
let assets_path = config_parent.join(path);
184184
if !assets_path.exists() {
185185
panic!(
186-
"The `frontendDist` configuration is set to `{:?}` but this path doesn't exist",
187-
path
186+
"The `frontendDist` configuration is set to `{path:?}` but this path doesn't exist"
188187
)
189188
}
190189
EmbeddedAssets::new(assets_path, &options, map_core_assets(&options))?

core/tauri-utils/src/acl/build.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,6 @@ identifier = "deny-{slugified_command}"
435435
description = "Denies the {command} command without any pre-configured scope."
436436
commands.deny = ["{command}"]
437437
"###,
438-
command = command,
439-
slugified_command = slugified_command,
440438
);
441439

442440
let out_path = path.join(format!("{command}.toml"));

core/tauri/build.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ fn main() {
229229
alias("custom_protocol", custom_protocol);
230230
alias("dev", dev);
231231

232-
println!("cargo:dev={}", dev);
232+
println!("cargo:dev={dev}");
233233

234234
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
235235
let mobile = target_os == "ios" || target_os == "android";
@@ -257,10 +257,7 @@ fn main() {
257257
if let Ok(kotlin_out_dir) = std::env::var("WRY_ANDROID_KOTLIN_FILES_OUT_DIR") {
258258
fn env_var(var: &str) -> String {
259259
std::env::var(var).unwrap_or_else(|_| {
260-
panic!(
261-
"`{}` is not set, which is needed to generate the kotlin files for android.",
262-
var
263-
)
260+
panic!("`{var}` is not set, which is needed to generate the kotlin files for android.")
264261
})
265262
}
266263

@@ -346,7 +343,7 @@ fn define_permissions(out_dir: &Path) {
346343
.filter(|(_cmd, default)| *default)
347344
.map(|(cmd, _)| {
348345
let slugified_command = cmd.replace('_', "-");
349-
format!("\"allow-{}\"", slugified_command)
346+
format!("\"allow-{slugified_command}\"")
350347
})
351348
.collect::<Vec<_>>()
352349
.join(", ");

core/tauri/src/event/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,22 +175,20 @@ pub fn listen_js_script(
175175
) -> String {
176176
format!(
177177
"(function () {{
178-
if (window['{listeners}'] === void 0) {{
179-
Object.defineProperty(window, '{listeners}', {{ value: Object.create(null) }});
178+
if (window['{listeners_object_name}'] === void 0) {{
179+
Object.defineProperty(window, '{listeners_object_name}', {{ value: Object.create(null) }});
180180
}}
181-
if (window['{listeners}']['{event}'] === void 0) {{
182-
Object.defineProperty(window['{listeners}'], '{event}', {{ value: Object.create(null) }});
181+
if (window['{listeners_object_name}']['{event}'] === void 0) {{
182+
Object.defineProperty(window['{listeners_object_name}'], '{event}', {{ value: Object.create(null) }});
183183
}}
184-
const eventListeners = window['{listeners}']['{event}']
184+
const eventListeners = window['{listeners_object_name}']['{event}']
185185
const listener = {{
186-
target: {target},
186+
target: {serialized_target},
187187
handler: {handler}
188188
}};
189189
Object.defineProperty(eventListeners, '{event_id}', {{ value: listener, configurable: true }});
190190
}})()
191191
",
192-
listeners = listeners_object_name,
193-
target = serialized_target,
194192
)
195193
}
196194

core/tauri/src/manager/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -759,9 +759,7 @@ mod test {
759759
assert_eq!(
760760
received.len(),
761761
expected.len(),
762-
"received {:?} `{kind}` events but expected {:?}",
763-
received,
764-
expected
762+
"received {received:?} `{kind}` events but expected {expected:?}"
765763
);
766764
}
767765

core/tauri/src/test/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ mod tests {
314314
});
315315

316316
app.run(|_app, event| {
317-
println!("{:?}", event);
317+
println!("{event:?}");
318318
});
319319
}
320320
}

examples/commands/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn borrow_cmd_async(the_argument: &str) -> &str {
219219

220220
#[command]
221221
fn raw_request(request: Request<'_>) -> Response {
222-
println!("{:?}", request);
222+
println!("{request:?}");
223223
Response::new(include_bytes!("./README.md").to_vec())
224224
}
225225

0 commit comments

Comments
 (0)