Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: simplify string formatting #10259

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 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 @@ -168,12 +168,8 @@ fn copy_framework_from(src_dir: &Path, framework: &str, dest_dir: &Path) -> Resu

// Copies the macOS application bundle frameworks to the target folder
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
)
})?;
std::fs::create_dir_all(dest_dir)
.with_context(|| format!("Failed to create frameworks output directory at {dest_dir:?}"))?;
for framework in frameworks.iter() {
if framework.ends_with(".framework") {
let src_path = PathBuf::from(framework);
Expand Down Expand Up @@ -469,7 +465,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,
Comment on lines -438 to -439
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think these were necessary.

);

let out_path = path.join(format!("{command}.toml"));
Expand Down
9 changes: 3 additions & 6 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 @@ -257,10 +257,7 @@ fn main() {
if let Ok(kotlin_out_dir) = std::env::var("WRY_ANDROID_KOTLIN_FILES_OUT_DIR") {
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
)
panic!("`{var}` is not set, which is needed to generate the kotlin files for android.")
})
}

Expand Down Expand Up @@ -346,7 +343,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
Loading