From 45f3f5a945a48e3af028e1dbc57a4348d166716d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Thu, 28 Jan 2021 15:40:07 -0500 Subject: [PATCH] Simplify a few pattern matches A few pattern-matches correspond directly to standard combinators on `Result`, `Option`. This uses them for concision / clarity. Refactorings reviewed by the author after suggestion from [comby-rust](https://github.com/huitseeker/comby-rust). --- zcash_primitives/src/transaction/builder.rs | 5 +---- zcash_primitives/src/zip32.rs | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/zcash_primitives/src/transaction/builder.rs b/zcash_primitives/src/transaction/builder.rs index a055c9e01..051d29218 100644 --- a/zcash_primitives/src/transaction/builder.rs +++ b/zcash_primitives/src/transaction/builder.rs @@ -123,10 +123,7 @@ impl SaplingOutput { value: Amount, memo: Option, ) -> Result { - let g_d = match to.g_d() { - Some(g_d) => g_d, - None => return Err(Error::InvalidAddress), - }; + let g_d = to.g_d().ok_or(Error::InvalidAddress)?; if value.is_negative() { return Err(Error::InvalidAmount); } diff --git a/zcash_primitives/src/zip32.rs b/zcash_primitives/src/zip32.rs index fb8240d87..b06e471a4 100644 --- a/zcash_primitives/src/zip32.rs +++ b/zcash_primitives/src/zip32.rs @@ -429,10 +429,7 @@ impl ExtendedFullViewingKey { } pub fn address(&self, j: DiversifierIndex) -> Result<(DiversifierIndex, PaymentAddress), ()> { - let (j, d_j) = match self.dk.diversifier(j) { - Ok(ret) => ret, - Err(()) => return Err(()), - }; + let (j, d_j) = self.dk.diversifier(j)?; match self.fvk.vk.to_payment_address(d_j) { Some(addr) => Ok((j, addr)), None => Err(()),