diff --git a/src/config.rs b/src/config.rs index 9e63912..fd2dd51 100644 --- a/src/config.rs +++ b/src/config.rs @@ -211,7 +211,7 @@ impl Config { let re = Regex::new(r"https:\/\/.+\/app-web.*\.js").unwrap(); let url = re .find(&source) - .ok_or(Error::not_found("unable to find app-web source"))?; + .ok_or_else(|| Error::not_found("unable to find app-web source"))?; // Get the app-web source. let url = url.as_str(); @@ -222,11 +222,11 @@ impl Config { let re = Regex::new(r"0x61%2C(0x[0-9a-f]{2}%2C){6}0x67").unwrap(); let a = re .find(&source) - .ok_or(Error::not_found("unable to find first half of secret key"))?; + .ok_or_else(|| Error::not_found("unable to find first half of secret key"))?; let re = Regex::new(r"0x31%2C(0x[0-9a-f]{2}%2C){6}0x34").unwrap(); let b = re .find(&source) - .ok_or(Error::not_found("unable to find second half of secret key"))?; + .ok_or_else(|| Error::not_found("unable to find second half of secret key"))?; let a = Self::convert_half(a.as_str())?; let b = Self::convert_half(b.as_str())?; diff --git a/src/decoder.rs b/src/decoder.rs index 92a0041..facd3e4 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -227,7 +227,7 @@ impl Decoder { .format; let default_track = demuxer .default_track() - .ok_or(Error::not_found("default track not found"))?; + .ok_or_else(|| Error::not_found("default track not found"))?; let codec_params = &default_track.codec_params; let decoder = codecs.make(codec_params, &DecoderOptions::default())?; diff --git a/src/main.rs b/src/main.rs index 82b14f6..b24a049 100644 --- a/src/main.rs +++ b/src/main.rs @@ -354,11 +354,11 @@ async fn run(args: Args) -> Result { let email = secrets .get("email") .and_then(|email| email.as_str()) - .ok_or(Error::unauthenticated("email not found"))?; + .ok_or_else(|| Error::unauthenticated("email not found"))?; let password = secrets .get("password") .and_then(|password| password.as_str()) - .ok_or(Error::unauthenticated("password not found"))?; + .ok_or_else(|| Error::unauthenticated("password not found"))?; Credentials::Login { email: email.to_string(), diff --git a/src/player.rs b/src/player.rs index 249fd95..27b78b8 100644 --- a/src/player.rs +++ b/src/player.rs @@ -688,7 +688,7 @@ impl Player { let sources = self .sources .as_mut() - .ok_or(Error::unavailable("audio sources not available"))?; + .ok_or_else(|| Error::unavailable("audio sources not available"))?; if track.handle().is_none() { let download = tokio::time::timeout(Self::NETWORK_TIMEOUT, async { @@ -930,7 +930,7 @@ impl Player { fn sink_mut(&mut self) -> Result<&mut rodio::Sink> { self.sink .as_mut() - .ok_or(Error::unavailable("audio sink not available")) + .ok_or_else(|| Error::unavailable("audio sink not available")) } /// Starts or resumes playback. @@ -1419,7 +1419,7 @@ impl Player { // This prevents stalling the player when seeking in a track that has not started. match track .handle() - .ok_or(Error::unavailable("download not yet started")) + .ok_or_else(|| Error::unavailable("download not yet started")) .and_then(|_| { self.sink_mut() .and_then(|sink| sink.try_seek(position).map_err(Into::into)) diff --git a/src/proxy.rs b/src/proxy.rs index dcab4b7..964986b 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -66,6 +66,9 @@ pub struct Http { url: String, } +/// Default HTTPS port. +const HTTPS_PORT: u16 = 443; + impl Http { /// Creates proxy configuration from environment. /// @@ -108,8 +111,8 @@ impl Http { let target_url = Url::parse(target)?; let host = target_url .host_str() - .ok_or(Error::invalid_argument("target host not available"))?; - let port = target_url.port().unwrap_or(443); + .ok_or_else(|| Error::invalid_argument("target host not available"))?; + let port = target_url.port().unwrap_or(HTTPS_PORT); let tcp_stream = TcpStream::connect(&self.url).await?; Self::tunnel(tcp_stream, host, port, self.auth.as_ref()).await } diff --git a/src/remote.rs b/src/remote.rs index 23f9b64..2ed0bab 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -1970,7 +1970,7 @@ impl Client { let queue = self .queue .as_ref() - .ok_or(Error::internal("no active queue"))?; + .ok_or_else(|| Error::internal("no active queue"))?; let player_position = self.player.position(); let mut position = player_position;