소스 검색

fix: use clippy fix

mrxiaozhuox 3 년 전
부모
커밋
1c2cf3330e
7개의 변경된 파일22개의 추가작업 그리고 24개의 파일을 삭제
  1. 2 2
      src/builder.rs
  2. 3 3
      src/cargo.rs
  3. 1 1
      src/cli/build/mod.rs
  4. 1 1
      src/cli/clean/mod.rs
  5. 1 1
      src/cli/serve/mod.rs
  6. 1 1
      src/cli/translate/mod.rs
  7. 13 15
      src/server/mod.rs

+ 2 - 2
src/builder.rs

@@ -187,7 +187,7 @@ pub fn build_desktop(config: &CrateConfig) -> Result<()> {
                 .application
                 .out_dir
                 .clone()
-                .unwrap_or(PathBuf::from("dist"))
+                .unwrap_or_else(|| PathBuf::from("dist"))
                 .display()
         );
     }
@@ -238,7 +238,7 @@ pub fn gen_page(config: &DioxusConfig, serve: bool) -> String {
 
     html = html.replace("{app_name}", &config.application.name);
 
-    let title = config.web.app.title.clone().unwrap_or("dioxus | ⛺".into());
+    let title = config.web.app.title.clone().unwrap_or_else(|| "dioxus | ⛺".into());
 
     html.replace("{app_title}", &title)
 }

+ 3 - 3
src/cargo.rs

@@ -1,6 +1,6 @@
 //! Utilities for working with cargo and rust files
 use crate::error::{Error, Result};
-use std::{env, fs, path::PathBuf, process::Command, str};
+use std::{env, fs, path::{PathBuf, Path}, process::Command, str};
 
 /// How many parent folders are searched for a `Cargo.toml`
 const MAX_ANCESTORS: u32 = 10;
@@ -44,7 +44,7 @@ pub fn workspace_root() -> Result<PathBuf> {
     }
 
     let stdout = str::from_utf8(&output.stdout).unwrap();
-    for line in stdout.lines() {
+    if let Some(line) = stdout.lines().next() {
         let meta: serde_json::Value = serde_json::from_str(line)
             .map_err(|_| Error::CargoError("InvalidOutput".to_string()))?;
 
@@ -58,7 +58,7 @@ pub fn workspace_root() -> Result<PathBuf> {
 }
 
 /// Checks if the directory contains `Cargo.toml`
-fn contains_manifest(path: &PathBuf) -> bool {
+fn contains_manifest(path: &Path) -> bool {
     fs::read_dir(path)
         .map(|entries| {
             entries

+ 1 - 1
src/cli/build/mod.rs

@@ -39,7 +39,7 @@ impl Build {
                         .application
                         .out_dir
                         .clone()
-                        .unwrap_or(PathBuf::from("dist")),
+                        .unwrap_or_else(|| PathBuf::from("dist")),
                 )
                 .join("index.html"),
         )?;

+ 1 - 1
src/cli/clean/mod.rs

@@ -30,7 +30,7 @@ impl Clean {
             .dioxus_config
             .application
             .out_dir
-            .unwrap_or(PathBuf::from("dist"));
+            .unwrap_or_else(|| PathBuf::from("dist"));
         if crate_config.crate_dir.join(&out_dir).is_dir() {
             remove_dir_all(crate_config.crate_dir.join(&out_dir))?;
         }

+ 1 - 1
src/cli/serve/mod.rs

@@ -62,7 +62,7 @@ impl Serve {
                         .application
                         .out_dir
                         .clone()
-                        .unwrap_or(PathBuf::from("dist")),
+                        .unwrap_or_else(|| PathBuf::from("dist")),
                 )
                 .join("index.html"),
         )?;

+ 1 - 1
src/cli/translate/mod.rs

@@ -48,7 +48,7 @@ impl Translate {
                 exit(0);
             })
         });
-        if temp.is_none() {
+        if let Some(..) = temp {
             if let Some(s) = source {
                 contents = s;
             } else {

+ 13 - 15
src/server/mod.rs

@@ -49,7 +49,7 @@ pub async fn startup(config: CrateConfig) -> anyhow::Result<()> {
             .watcher
             .watch_path
             .clone()
-            .unwrap_or(vec![PathBuf::from("src")]);
+            .unwrap_or_else(|| vec![PathBuf::from("src")]);
         let crate_dir = watcher_conf.crate_dir.clone();
         loop {
             if let Ok(v) = rx.recv() {
@@ -67,21 +67,19 @@ pub async fn startup(config: CrateConfig) -> anyhow::Result<()> {
                             }
                         }
 
-                        if reload {
-                            if let Ok(_) = builder::build(&watcher_conf) {
-                                // change the websocket reload state to true;
-                                // the page will auto-reload.
-                                if watcher_conf
-                                    .dioxus_config
-                                    .web
-                                    .watcher
-                                    .reload_html
-                                    .unwrap_or(false)
-                                {
-                                    let _ = Serve::regen_dev_page(&watcher_conf);
-                                }
-                                watcher_ws_state.lock().unwrap().change();
+                        if reload && builder::build(&watcher_conf).is_ok() {
+                            // change the websocket reload state to true;
+                            // the page will auto-reload.
+                            if watcher_conf
+                                .dioxus_config
+                                .web
+                                .watcher
+                                .reload_html
+                                .unwrap_or(false)
+                            {
+                                let _ = Serve::regen_dev_page(&watcher_conf);
                             }
+                            watcher_ws_state.lock().unwrap().change();
                         }
                     }
                     _ => {}