fix: use clippy fix

This commit is contained in:
mrxiaozhuox 2022-01-25 12:42:27 +08:00
parent 66b832045a
commit 84d1867654
9 changed files with 36 additions and 44 deletions

View file

@ -157,16 +157,16 @@ pub fn build_desktop(config: &CrateConfig) -> Result<()> {
file_name = name.clone();
config
.target_dir
.join(format!("{}", release_type))
.join(format!("{}", name))
.join(release_type.to_string())
.join(name.to_string())
}
crate::ExecutableType::Example(name) => {
file_name = name.clone();
config
.target_dir
.join(format!("{}", release_type))
.join(release_type.to_string())
.join("examples")
.join(format!("{}", name))
.join(name.to_string())
}
};
@ -175,7 +175,7 @@ pub fn build_desktop(config: &CrateConfig) -> Result<()> {
res_path.set_extension("exe");
target_file = format!("{}.exe", &file_name);
} else {
target_file = file_name.clone();
target_file = file_name;
}
create_dir_all(&config.out_dir)?;
copy(res_path, &config.out_dir.join(target_file))?;
@ -200,12 +200,12 @@ pub fn gen_page(config: &DioxusConfig, serve: bool) -> String {
let resouces = config.web.resource.clone();
let mut style_list = resouces.style.unwrap_or(vec![]);
let mut script_list = resouces.script.unwrap_or(vec![]);
let mut style_list = resouces.style.unwrap_or_default();
let mut script_list = resouces.script.unwrap_or_default();
if serve {
let mut dev_style = resouces.dev.style.clone().unwrap_or(vec![]);
let mut dev_script = resouces.dev.script.clone().unwrap_or(vec![]);
let mut dev_style = resouces.dev.style.clone().unwrap_or_default();
let mut dev_script = resouces.dev.script.unwrap_or_default();
style_list.append(&mut dev_style);
script_list.append(&mut dev_script);
}

View file

@ -22,10 +22,8 @@ impl Build {
crate_config.as_example(self.build.example.unwrap());
}
if self.build.platform.is_some() {
if self.build.platform.unwrap().to_uppercase() == "DESKTOP" {
crate::builder::build_desktop(&crate_config)?;
}
if self.build.platform.is_some() && self.build.platform.unwrap().to_uppercase() == "DESKTOP" {
crate::builder::build_desktop(&crate_config)?;
}
crate::builder::build(&crate_config)?;

View file

@ -25,7 +25,7 @@ impl Config {
match self {
Config::Init { name, force } => {
let conf_path = crate_root.join("Dioxus.toml");
if conf_path.is_file() && force == false {
if conf_path.is_file() && !force {
log::warn!(
"config file `Dioxus.toml` already exist, use `--force` to overwrite it."
);

View file

@ -83,7 +83,7 @@ impl Create {
meta_file = meta_file.replace("{{project-name}}", &self.name);
File::create(project_path.join("Dioxus.toml"))?.write_all(meta_file.as_bytes())?;
println!("");
println!();
log::info!("💡 Project initialized:");
log::info!("🎯> cd ./{}", self.name);
log::info!("🎯> dioxus serve");

View file

@ -21,27 +21,22 @@ impl Serve {
crate_config.as_example(self.serve.example.unwrap());
}
if self.serve.platform.is_some() {
if self.serve.platform.unwrap().to_uppercase() == "DESKTOP" {
crate::builder::build_desktop(&crate_config)?;
if self.serve.platform.is_some() && self.serve.platform.unwrap().to_uppercase() == "DESKTOP" {
crate::builder::build_desktop(&crate_config)?;
match &crate_config.executable {
crate::ExecutableType::Binary(name)
| crate::ExecutableType::Lib(name)
| crate::ExecutableType::Example(name) => {
let mut file = crate_config.out_dir.join(name);
if cfg!(windows) {
file.set_extension("exe");
}
Command::new(format!(
"{}",
crate_config.out_dir.join(file).to_str().unwrap()
))
.output()?;
match &crate_config.executable {
crate::ExecutableType::Binary(name)
| crate::ExecutableType::Lib(name)
| crate::ExecutableType::Example(name) => {
let mut file = crate_config.out_dir.join(name);
if cfg!(windows) {
file.set_extension("exe");
}
Command::new(crate_config.out_dir.join(file).to_str().unwrap().to_string())
.output()?;
}
return Ok(());
}
return Ok(());
}
crate::builder::build(&crate_config).expect("build failed");

View file

@ -48,7 +48,7 @@ impl Translate {
exit(0);
})
});
if let None = temp {
if temp.is_none() {
if let Some(s) = source {
contents = s;
} else {
@ -112,7 +112,7 @@ fn render_child(f: &mut impl Write, child: &Node, il: u32) -> std::fmt::Result {
}
write!(f, "\",")?;
}
write!(f, "\n")?;
writeln!(f)?;
// write the attributes
if let Some(id) = &el.id {

View file

@ -120,7 +120,7 @@ fn render_element<'a>(
}
write!(f, "\",")?;
}
write!(f, "\n")?;
writeln!(f)?;
// write the attributes
if let Some(id) = &el.id {

View file

@ -23,12 +23,12 @@ impl DioxusConfig {
dioxus_conf_file.read_to_string(&mut meta_str)?;
match toml::from_str::<DioxusConfig>(&meta_str) {
Ok(v) => return Ok(v),
Ok(v) => Ok(v),
Err(e) => {
log::error!("{}", e);
return Err(crate::error::Error::Unique(
Err(crate::error::Error::Unique(
"Dioxus.toml parse failed".into(),
));
))
}
}
}
@ -147,16 +147,15 @@ impl CrateConfig {
// We just assume they're using a 'main.rs'
// Anyway, we've already parsed the manifest, so it should be easy to change the type
let output_filename = (&manifest)
let output_filename = manifest
.lib
.as_ref()
.and_then(|lib| lib.name.clone())
.or_else(|| {
(&manifest)
manifest
.package
.as_ref()
.and_then(|pkg| Some(pkg.name.clone()))
.clone()
.as_ref().map(|pkg| pkg.name.clone())
})
.expect("No lib found from cargo metadata");
let executable = ExecutableType::Binary(output_filename);

View file

@ -14,7 +14,7 @@ pub fn set_up_logging() {
// configure colors for the name of the level.
// since almost all of them are the same as the color for the whole line, we
// just clone `colors_line` and overwrite our changes
let colors_level = colors_line.clone().info(Color::Green);
let colors_level = colors_line.info(Color::Green);
// here we set up our fern Dispatch
fern::Dispatch::new()
.format(move |out, message, record| {