src: Implemented clippy recommendations

Should make some code look less silly.
This commit is contained in:
Lux Aliaga 2022-10-01 17:38:14 -03:00
parent b627d304d8
commit 4712c67bc2
Signed by: lux
GPG Key ID: B56C805968637437
4 changed files with 26 additions and 26 deletions

View File

@ -31,10 +31,10 @@ fn main() -> Result<()> {
create_dir_all(tempdir.clone())?;
for page in 0..pages.len() {
let tempfile = tempdir.join(pages[page].clone().1);
for page in &pages {
let tempfile = tempdir.join(page.clone().1);
let mut file = File::create(tempfile).unwrap();
write!(&mut file, "{}", pages[page].clone().0).unwrap();
write!(&mut file, "{}", page.clone().0).unwrap();
}
}
Ok(())

View File

@ -31,13 +31,13 @@ pub fn env_config() -> Result<Vec<PathBuf>> {
if home == PathBuf::new() {
bail!("{}", "Vento was unable to detect your home folder. Have you configured your environment correctly?".red());
};
let vento_dir: PathBuf;
let custom_dir = Path::new(&dir_config()?).to_path_buf();
if custom_dir != PathBuf::new() {
vento_dir = Path::new(&custom_dir).to_path_buf();
let vento_dir: PathBuf = if custom_dir != PathBuf::new() {
Path::new(&custom_dir).to_path_buf()
} else {
vento_dir = [home, Path::new(".vento").to_path_buf()].iter().collect();
}
[home, Path::new(".vento").to_path_buf()].iter().collect()
};
let active_dir = [&vento_dir, &Path::new("active").to_path_buf()]
.iter()
.collect();
@ -56,7 +56,7 @@ fn dir_config() -> Result<String> {
_ => PathBuf::new(),
};
if &config != &PathBuf::new() {
if config != PathBuf::new() {
config.push("vento.toml");
if config.is_file() {
let settings = Config::builder()

View File

@ -32,7 +32,7 @@ pub fn init() -> Result<()> {
if ventodir.is_dir() {
// Checks if Vento has already been initialized and prompts the user if they want to initialize it again
let mut answer = String::new();
print!("⚠️ {} {}", "WARNING:".bold().red(), "Vento has already been initialized. Reinitializing will delete all files on the directory for Vento. Do you wish to proceed? (y/N) ");
print!("⚠️ {} Vento has already been initialized. Reinitializing will delete all files on the directory for Vento. Do you wish to proceed? (y/N) ", "WARNING:".bold().red());
let _ = io::stdout().flush();
io::stdin()
.read_line(&mut answer)
@ -65,7 +65,7 @@ pub fn list(slot: &str, dir: &str) -> Result<()> {
_ => PathBuf::new(),
};
if dir != "" {
if !dir.is_empty() {
// Detects if the directory argument is not empty, and if so appends the path provided to the slot directory variable
slotdir = [&slotdir, &Path::new(dir).to_path_buf()].iter().collect();
}
@ -95,14 +95,14 @@ pub fn list(slot: &str, dir: &str) -> Result<()> {
format!(
"No files in {}{}.",
match slot {
"active" => format!("{}", slot).bold(),
"inactive" | _ => format!("{}", slot).blue().bold(),
"active" => slot.bold(),
_ => slot.blue().bold(),
},
if dir != "" {
if !dir.is_empty() {
if cfg!(windows) {
format!("\\{}", dir.to_string())
format!("\\{}", dir)
} else {
format!("/{}", dir.to_string())
format!("/{}", dir)
}
} else {
"".to_string()
@ -116,14 +116,14 @@ pub fn list(slot: &str, dir: &str) -> Result<()> {
format!(
"Files in {}{} ({}):",
match slot {
"active" => format!("{}", slot).bold(),
"inactive" | _ => format!("{}", slot).blue().bold(),
"active" => slot.bold(),
_ => slot.blue().bold(),
},
if dir != "" {
if !dir.is_empty() {
if cfg!(windows) {
format!("\\{}", dir.to_string())
format!("\\{}", dir)
} else {
format!("/{}", dir.to_string())
format!("/{}", dir)
}
} else {
" inventory".to_string()
@ -158,7 +158,7 @@ pub fn list(slot: &str, dir: &str) -> Result<()> {
SizeFormatterBinary::new(file.clone().metadata().unwrap().len())
)
} else {
format!("")
String::new()
}
);
}

View File

@ -24,7 +24,7 @@ use fs_extra::dir::{move_dir, CopyOptions};
use std::fs;
use std::path::{Path, PathBuf};
pub fn take(file: &String, slot: &String) -> Result<()> {
pub fn take(file: &String, slot: &str) -> Result<()> {
// Takes a file or directory
let ventodir = &common::env_config()?[0];
@ -35,7 +35,7 @@ pub fn take(file: &String, slot: &String) -> Result<()> {
"Vento not initialized. Run \"vento -i\" to initialize Vento.".red()
);
};
let slotdir: PathBuf = match slot.as_str() {
let slotdir: PathBuf = match slot {
"active" | "a" => common::env_config()?[1].clone(),
"inactive" | "i" => common::env_config()?[2].clone(),
_ => PathBuf::new(),
@ -92,7 +92,7 @@ pub fn take(file: &String, slot: &String) -> Result<()> {
Ok(())
}
pub fn drop(file: &String, slot: &String, dest: PathBuf) -> Result<()> {
pub fn drop(file: &String, slot: &str, dest: PathBuf) -> Result<()> {
// Drops a file or directory
let ventodir = &common::env_config()?[0];
@ -104,7 +104,7 @@ pub fn drop(file: &String, slot: &String, dest: PathBuf) -> Result<()> {
);
};
let slotdir: PathBuf = match slot.as_str() {
let slotdir: PathBuf = match slot {
"active" | "a" => common::env_config()?[1].clone(),
"inactive" | "i" => common::env_config()?[2].clone(),
_ => PathBuf::new(),