]> Untitled Git - bdk/commitdiff
Use `unwrap_or_else`
authorTobin Harding <me@tobin.cc>
Mon, 21 Dec 2020 09:08:24 +0000 (20:08 +1100)
committerTobin Harding <me@tobin.cc>
Wed, 24 Feb 2021 02:30:46 +0000 (13:30 +1100)
As directed by clippy use `unwrap_or_else` in order to take advantage of
lazy evaluation.

testutils/src/lib.rs

index 15b920c89cf98d9a7aa5afdd0fd4c2d48db97d43..c60573e273ee1e2eed39290a79fc506dbb0a1099 100644 (file)
@@ -60,13 +60,13 @@ fn get_auth() -> Auth {
         ),
         _ => Auth::CookieFile(PathBuf::from(
             env::var("BDK_RPC_COOKIEFILE")
-                .unwrap_or("/home/user/.bitcoin/regtest/.cookie".to_string()),
+                .unwrap_or_else(|_| "/home/user/.bitcoin/regtest/.cookie".to_string()),
         )),
     }
 }
 
 pub fn get_electrum_url() -> String {
-    env::var("BDK_ELECTRUM_URL").unwrap_or("tcp://127.0.0.1:50001".to_string())
+    env::var("BDK_ELECTRUM_URL").unwrap_or_else(|_| "tcp://127.0.0.1:50001".to_string())
 }
 
 pub struct TestClient {
@@ -311,8 +311,8 @@ where
 
 impl TestClient {
     pub fn new() -> Self {
-        let url = env::var("BDK_RPC_URL").unwrap_or("127.0.0.1:18443".to_string());
-        let wallet = env::var("BDK_RPC_WALLET").unwrap_or("bdk-test".to_string());
+        let url = env::var("BDK_RPC_URL").unwrap_or_else(|_| "127.0.0.1:18443".to_string());
+        let wallet = env::var("BDK_RPC_WALLET").unwrap_or_else(|_| "bdk-test".to_string());
         let client =
             RpcClient::new(format!("http://{}/wallet/{}", url, wallet), get_auth()).unwrap();
         let electrum = ElectrumClient::new(&get_electrum_url()).unwrap();