clippy clean

This commit is contained in:
Penwing 2024-01-26 09:15:02 +01:00
parent 1277870097
commit 5fedd82dda
2 changed files with 200 additions and 205 deletions

View file

@ -1,6 +1,6 @@
use eframe::egui;
use egui::Color32;
use std::{cmp::min, fs, io, path::Path, path::PathBuf, ffi::OsStr};
use std::{cmp::min, ffi::OsStr, fs, io, path::Path, path::PathBuf};
use crate::tools;
use crate::Calcifer;
@ -143,11 +143,9 @@ impl Calcifer {
return Ok(());
}
egui::CollapsingHeader::new(name).show(ui, |ui| {
match fs::read_dir(path) {
egui::CollapsingHeader::new(name).show(ui, |ui| match fs::read_dir(path) {
Err(err) => {
ui.label(format!("Error reading directory: {}", err));
return;
}
Ok(entries) => {
let mut paths: Vec<Result<fs::DirEntry, io::Error>> = entries
@ -155,9 +153,7 @@ impl Calcifer {
.collect();
paths.sort_by(|a, b| match (a, b) {
(Ok(entry_a), Ok(entry_b)) => {
tools::sort_directories_first(&entry_a, &entry_b)
}
(Ok(entry_a), Ok(entry_b)) => tools::sort_directories_first(entry_a, entry_b),
(Err(_), Ok(_)) => std::cmp::Ordering::Greater,
(Ok(_), Err(_)) => std::cmp::Ordering::Less,
(Err(_), Err(_)) => std::cmp::Ordering::Equal,
@ -174,7 +170,6 @@ impl Calcifer {
}
}
}
}
});
Ok(())
}

View file

@ -1,5 +1,5 @@
use eframe::egui::text_edit::CCursorRange;
use std::{fs::read_to_string, path::PathBuf};
use std::{fs::read_to_string, path::Path, path::PathBuf};
use crate::MAX_TABS;
@ -85,16 +85,16 @@ impl Tab {
}
}
fn read_file_contents(path: &PathBuf) -> String {
read_to_string(path.clone())
fn read_file_contents(path: &Path) -> String {
read_to_string(path.to_path_buf())
.map_err(|err| format!("// Error reading file: {}", err))
.unwrap_or_else(|err_msg| err_msg)
}
fn format_file_path(path: &PathBuf, contents: &str) -> PathBuf {
fn format_file_path(path: &Path, contents: &str) -> PathBuf {
if contents.contains("Error reading file") {
"untitled".into()
} else {
path.clone()
path.to_path_buf()
}
}