From 69193d9f94459ba3a194047f106663b5eeb2db1d Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Wed, 21 Feb 2024 19:25:15 +0200 Subject: [PATCH] use result for better error handling dx --- src/dl.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/dl.rs b/src/dl.rs index b885e76..9c101f4 100644 --- a/src/dl.rs +++ b/src/dl.rs @@ -10,7 +10,7 @@ pub mod yt_dlp; pub enum DownloadError { Message(String), NoFormatFound, - MakePathError + MakePathError, } impl From for DownloadError { @@ -25,12 +25,12 @@ impl From for DownloadError { } } -fn make_download_path(info: &YtDlpInfo, format: &YtDlpFormat) -> Option { +fn make_download_path(info: &YtDlpInfo, format: &YtDlpFormat) -> Result { std::env::temp_dir() .join(format!("{}.{}", info.id, format.ext)) .into_os_string() .into_string() - .ok() + .map_err(|e| DownloadError::MakePathError) } pub async fn download(url: &str) -> Result { @@ -39,10 +39,7 @@ pub async fn download(url: &str) -> Result { Some(av) => av, None => return Err(DownloadError::NoFormatFound), }; - let output_path = match make_download_path(&info, &av) { - Some(path) => path, - None => return Err(DownloadError::MakePathError) - }; + let output_path = make_download_path(&info, &av)?; todo!() }