diff --git a/src/file_sink.rs b/src/file_sink.rs index 8cfd812..966694b 100644 --- a/src/file_sink.rs +++ b/src/file_sink.rs @@ -22,16 +22,13 @@ impl FileSink { } impl Open for FileSink { + // use the unwrap_or_else method instead of the if let statement to handle the absence of a path value fn open(path: Option, _audio_format: AudioFormat) -> Self { - if let Some(path) = path { - let file = path; - FileSink { - sink: file, - content: Vec::new(), - metadata: None - } - } else { - panic!(); + let file = path.unwrap_or_else(|| panic!()); + FileSink { + sink: file, + content: Vec::new(), + metadata: None } } } diff --git a/src/main.rs b/src/main.rs index c04a4b1..7d154d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod file_sink; extern crate rpassword; use std::{path::PathBuf}; +use std::path::Path; use librespot::{core::authentication::Credentials, metadata::Playlist}; use librespot::core::config::SessionConfig; @@ -82,15 +83,22 @@ async fn download_tracks(session: &Session, destination: PathBuf, tracks: Vec