Browse Source

style: simplify string formatting (#10259)

* style: simplfiy string formatting

* fix: file formatting in `core/`
Hamir Mahal 1 year ago
parent
commit
1a88fc1a9b

+ 4 - 8
core/tauri-build/src/lib.rs

@@ -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))?;
@@ -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);
@@ -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('_');

+ 3 - 3
core/tauri-build/src/mobile.rs

@@ -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;
 
@@ -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}"));
     }
   }
 

+ 1 - 2
core/tauri-codegen/src/context.rs

@@ -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))?

+ 0 - 2
core/tauri-utils/src/acl/build.rs

@@ -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"));

+ 3 - 6
core/tauri/build.rs

@@ -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";
@@ -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.")
         })
       }
 
@@ -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(", ");

+ 6 - 8
core/tauri/src/event/mod.rs

@@ -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,
   )
 }
 

+ 1 - 3
core/tauri/src/manager/mod.rs

@@ -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:?}"
     );
   }
 

+ 1 - 1
core/tauri/src/test/mod.rs

@@ -314,7 +314,7 @@ mod tests {
     });
 
     app.run(|_app, event| {
-      println!("{:?}", event);
+      println!("{event:?}");
     });
   }
 }

+ 1 - 1
examples/commands/main.rs

@@ -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())
 }