fix: use clippy fix

This commit is contained in:
mrxiaozhuox 2022-01-25 13:52:33 +08:00
parent 84d1867654
commit 1c2cf3330e
7 changed files with 22 additions and 24 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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();
}
}
_ => {}