From: Tobin Harding Date: Mon, 21 Dec 2020 09:08:24 +0000 (+1100) Subject: Use `unwrap_or_else` X-Git-Tag: v0.5.0~10^2~20 X-Git-Url: http://internal-gitweb-vhost/script/%22https:/database/struct.EncoderStringWriter.html?a=commitdiff_plain;h=5eaa3b0916055f54861ddec7e1e8a83ff62ea36b;p=bdk Use `unwrap_or_else` As directed by clippy use `unwrap_or_else` in order to take advantage of lazy evaluation. --- diff --git a/testutils/src/lib.rs b/testutils/src/lib.rs index 15b920c8..c60573e2 100644 --- a/testutils/src/lib.rs +++ b/testutils/src/lib.rs @@ -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();