Skip to content

Commit

Permalink
style: simplfiy string formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hamirmahal committed Jul 11, 2024
1 parent 2b1ceb4 commit a138eb8
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 28 deletions.
7 changes: 3 additions & 4 deletions core/tauri-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ fn copy_dir(from: &Path, to: &Path) -> Result<()> {

// Copies the framework under `{src_dir}/{framework}.framework` to `{dest_dir}/{framework}.framework`.
fn copy_framework_from(src_dir: &Path, framework: &str, dest_dir: &Path) -> Result<bool> {
let src_name = format!("{}.framework", framework);
let src_name = format!("{framework}.framework");
let src_path = src_dir.join(&src_name);
if src_path.exists() {
copy_dir(&src_path, &dest_dir.join(&src_name))?;
Expand All @@ -170,8 +170,7 @@ fn copy_framework_from(src_dir: &Path, framework: &str, dest_dir: &Path) -> Resu
fn copy_frameworks(dest_dir: &Path, frameworks: &[String]) -> Result<()> {
std::fs::create_dir_all(dest_dir).with_context(|| {
format!(
"Failed to create frameworks output directory at {:?}",
dest_dir
"Failed to create frameworks output directory at {dest_dir:?}"
)
})?;
for framework in frameworks.iter() {
Expand Down Expand Up @@ -469,7 +468,7 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
let mut android_package_prefix = String::new();
for (i, w) in s.enumerate() {
if i == last {
println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={}", w);
println!("cargo:rustc-env=TAURI_ANDROID_PACKAGE_NAME_APP_NAME={w}");
} else {
android_package_prefix.push_str(w);
android_package_prefix.push('_');
Expand Down
6 changes: 3 additions & 3 deletions core/tauri-build/src/mobile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ dependencies {"
app_build_gradle.push_str("\n}");

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

Expand All @@ -76,7 +76,7 @@ dependencies {"
));
}

app_tauri_properties.push(format!("tauri.android.versionCode={}", version_code));
app_tauri_properties.push(format!("tauri.android.versionCode={version_code}"));
}
}

Expand Down
3 changes: 1 addition & 2 deletions core/tauri-codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
let assets_path = config_parent.join(path);
if !assets_path.exists() {
panic!(
"The `frontendDist` configuration is set to `{:?}` but this path doesn't exist",
path
"The `frontendDist` configuration is set to `{path:?}` but this path doesn't exist"
)
}
EmbeddedAssets::new(assets_path, &options, map_core_assets(&options))?
Expand Down
2 changes: 0 additions & 2 deletions core/tauri-utils/src/acl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,6 @@ identifier = "deny-{slugified_command}"
description = "Denies the {command} command without any pre-configured scope."
commands.deny = ["{command}"]
"###,
command = command,
slugified_command = slugified_command,
);

let out_path = path.join(format!("{command}.toml"));
Expand Down
7 changes: 3 additions & 4 deletions core/tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ fn main() {
alias("custom_protocol", custom_protocol);
alias("dev", dev);

println!("cargo:dev={}", dev);
println!("cargo:dev={dev}");

let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
let mobile = target_os == "ios" || target_os == "android";
Expand Down Expand Up @@ -258,8 +258,7 @@ fn main() {
fn env_var(var: &str) -> String {
std::env::var(var).unwrap_or_else(|_| {
panic!(
"`{}` is not set, which is needed to generate the kotlin files for android.",
var
"`{var}` is not set, which is needed to generate the kotlin files for android."
)
})
}
Expand Down Expand Up @@ -346,7 +345,7 @@ fn define_permissions(out_dir: &Path) {
.filter(|(_cmd, default)| *default)
.map(|(cmd, _)| {
let slugified_command = cmd.replace('_', "-");
format!("\"allow-{}\"", slugified_command)
format!("\"allow-{slugified_command}\"")
})
.collect::<Vec<_>>()
.join(", ");
Expand Down
14 changes: 6 additions & 8 deletions core/tauri/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,20 @@ pub fn listen_js_script(
) -> String {
format!(
"(function () {{
if (window['{listeners}'] === void 0) {{
Object.defineProperty(window, '{listeners}', {{ value: Object.create(null) }});
if (window['{listeners_object_name}'] === void 0) {{
Object.defineProperty(window, '{listeners_object_name}', {{ value: Object.create(null) }});
}}
if (window['{listeners}']['{event}'] === void 0) {{
Object.defineProperty(window['{listeners}'], '{event}', {{ value: Object.create(null) }});
if (window['{listeners_object_name}']['{event}'] === void 0) {{
Object.defineProperty(window['{listeners_object_name}'], '{event}', {{ value: Object.create(null) }});
}}
const eventListeners = window['{listeners}']['{event}']
const eventListeners = window['{listeners_object_name}']['{event}']
const listener = {{
target: {target},
target: {serialized_target},
handler: {handler}
}};
Object.defineProperty(eventListeners, '{event_id}', {{ value: listener, configurable: true }});
}})()
",
listeners = listeners_object_name,
target = serialized_target,
)
}

Expand Down
4 changes: 1 addition & 3 deletions core/tauri/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,9 +759,7 @@ mod test {
assert_eq!(
received.len(),
expected.len(),
"received {:?} `{kind}` events but expected {:?}",
received,
expected
"received {received:?} `{kind}` events but expected {expected:?}"
);
}

Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ mod tests {
});

app.run(|_app, event| {
println!("{:?}", event);
println!("{event:?}");
});
}
}
2 changes: 1 addition & 1 deletion examples/commands/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ fn borrow_cmd_async(the_argument: &str) -> &str {

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

Expand Down

0 comments on commit a138eb8

Please sign in to comment.