From 29635b9e3833296b2c908914104ba7165d22d3d5 Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 12:03:13 +0200 Subject: remove `# Panics` and fix clippy --- src/files.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/files.rs') diff --git a/src/files.rs b/src/files.rs index 59f9ed1..636c934 100644 --- a/src/files.rs +++ b/src/files.rs @@ -19,7 +19,6 @@ use crate::{ }; /// # Errors -/// # Panics pub async fn download_versions( list: List, config: Cfg, @@ -27,19 +26,19 @@ pub async fn download_versions( progress: &MultiProgress, progress_before: &ProgressBar, ) -> MLE<()> { - let cached = get_cached_versions(&config.cache); + let cached = get_cached_versions(&config.cache)?; let mut js = JoinSet::new(); - let style_spinner = ProgressStyle::with_template(STYLE_SPINNER).unwrap(); + let style_spinner = ProgressStyle::with_template(STYLE_SPINNER).map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))?; let all = progress.insert_before( progress_before, - ProgressBar::new(versions.len().try_into().unwrap()), + ProgressBar::new(versions.len().try_into().map_err(|_| MLErr::new(EType::Other, "ListStackLen"))?), ); all.set_style( ProgressStyle::with_template(STYLE_BAR_POS) - .unwrap() + .map_err(|_| MLErr::new(EType::LibIndicatif, "template error"))? .progress_chars(PROGRESS_CHARS), ); all.set_message(format!("âś“Downloading {}", list.id)); @@ -66,7 +65,6 @@ pub async fn download_versions( } /// # Errors -/// # Panics async fn download_version( config: Cfg, list: List, @@ -86,7 +84,7 @@ async fn download_version( if c.is_some() { progress.set_message(format!("Get {} from cache", version.id)); cache_msg = " (cached)"; - copy_cached_version(&c.unwrap(), &dl_path); + copy_cached_version(&c.unwrap(), &dl_path)?; } else { let files = version.files; let file = match files.clone().into_iter().find(|f| f.primary) { @@ -124,7 +122,6 @@ async fn download_version( } /// # Errors -/// # Panics async fn download_file( url: &str, path: &str, @@ -166,7 +163,6 @@ async fn download_file( } /// # Errors -/// # Panics pub fn disable_version( config: &Cfg, current_list: &List, @@ -184,7 +180,6 @@ pub fn disable_version( } /// # Errors -/// # Panics pub fn delete_version(list: &List, version: &str) -> MLE<()> { let file = get_file_path(list, version)?; @@ -194,7 +189,6 @@ pub fn delete_version(list: &List, version: &str) -> MLE<()> { } /// # Errors -/// # Panics pub fn get_file_path(list: &List, versionid: &str) -> MLE { let mut names: HashMap = HashMap::new(); for file in read_dir(&list.download_folder)? { @@ -220,7 +214,6 @@ pub fn get_file_path(list: &List, versionid: &str) -> MLE { } /// # Errors -/// # Panics pub fn get_downloaded_versions(list: &List) -> MLE> { let mut versions: HashMap = HashMap::new(); for file in read_dir(&list.download_folder)? { @@ -243,7 +236,6 @@ pub fn get_downloaded_versions(list: &List) -> MLE> { } /// # Errors -/// # Panics pub fn clean_list_dir(list: &List) -> MLE<()> { let dl_path = &list.download_folder; for entry in std::fs::read_dir(dl_path)? { -- cgit v1.2.3