From d2c55cc99ce1bde4f052d10a886ba686d32e51b4 Mon Sep 17 00:00:00 2001 From: Yujia Qiao Date: Wed, 9 Mar 2022 12:34:29 +0800 Subject: [PATCH] chore: make clippy happy --- src/client.rs | 2 +- src/config.rs | 6 +++--- src/helper.rs | 2 +- src/server.rs | 2 +- src/transport/tls.rs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/client.rs b/src/client.rs index 9c04944d..657e6662 100644 --- a/src/client.rs +++ b/src/client.rs @@ -33,7 +33,7 @@ pub async fn run_client( shutdown_rx: broadcast::Receiver, service_rx: mpsc::Receiver, ) -> Result<()> { - let config = config.client.ok_or(anyhow!( + let config = config.client.ok_or_else(|| anyhow!( "Try to run as a client, but the configuration is missing. Please add the `[client]` block" ))?; diff --git a/src/config.rs b/src/config.rs index 5ce96ce1..5d105344 100644 --- a/src/config.rs +++ b/src/config.rs @@ -289,18 +289,18 @@ impl Config { let tls_config = config .tls .as_ref() - .ok_or(anyhow!("Missing TLS configuration"))?; + .ok_or_else(|| anyhow!("Missing TLS configuration"))?; if is_server { tls_config .pkcs12 .as_ref() .and(tls_config.pkcs12_password.as_ref()) - .ok_or(anyhow!("Missing `pkcs12` or `pkcs12_password`"))?; + .ok_or_else(|| anyhow!("Missing `pkcs12` or `pkcs12_password`"))?; } else { tls_config .trusted_root .as_ref() - .ok_or(anyhow!("Missing `trusted_root`"))?; + .ok_or_else(|| anyhow!("Missing `trusted_root`"))?; } Ok(()) } diff --git a/src/helper.rs b/src/helper.rs index 0f4a3bda..68db8807 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -44,7 +44,7 @@ async fn to_socket_addr(addr: A) -> Result { lookup_host(addr) .await? .next() - .ok_or(anyhow!("Failed to lookup the host")) + .ok_or_else(|| anyhow!("Failed to lookup the host")) } pub fn host_port_pair(s: &str) -> Result<(&str, u16)> { diff --git a/src/server.rs b/src/server.rs index 57fb20a6..4c086402 100644 --- a/src/server.rs +++ b/src/server.rs @@ -676,7 +676,7 @@ async fn run_udp_connection_pool( let mut conn = data_ch_rx .recv() .await - .ok_or(anyhow!("No available data channels"))?; + .ok_or_else(|| anyhow!("No available data channels"))?; conn.write_all(&cmd).await?; let mut buf = [0u8; UDP_BUFFER_SIZE]; diff --git a/src/transport/tls.rs b/src/transport/tls.rs index 7204704e..c4f6579b 100644 --- a/src/transport/tls.rs +++ b/src/transport/tls.rs @@ -26,7 +26,7 @@ impl Transport for TlsTransport { fn new(config: &TransportConfig) -> Result { let tcp = TcpTransport::new(config)?; - let config = config.tls.as_ref().ok_or(anyhow!("Missing tls config"))?; + let config = config.tls.as_ref().ok_or_else(|| anyhow!("Missing tls config"))?; let connector = match config.trusted_root.as_ref() { Some(path) => {