From 65cfd951dc91ff593f9e967b77aa5c8558712fd2 Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Mon, 28 Aug 2023 10:48:15 +0200 Subject: [PATCH] Use if-let instead of match --- libwasmvm/src/iterator.rs | 30 ++++++++++++-------------- libwasmvm/src/storage.rs | 45 ++++++++++++++++++--------------------- 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/libwasmvm/src/iterator.rs b/libwasmvm/src/iterator.rs index 6b1774783..d6098cbf7 100644 --- a/libwasmvm/src/iterator.rs +++ b/libwasmvm/src/iterator.rs @@ -66,14 +66,13 @@ impl GoIter { } pub fn next(&mut self) -> BackendResult> { - let next = match self.vtable.next { - Some(f) => f, - None => { - let result = Err(BackendError::unknown( - "iterator vtable function 'next' not set", - )); - return (result, GasInfo::free()); - } + let next = if let Some(f) = self.vtable.next { + f + } else { + let result = Err(BackendError::unknown( + "iterator vtable function 'next' not set", + )); + return (result, GasInfo::free()); }; let mut output_key = UnmanagedVector::default(); @@ -140,14 +139,13 @@ impl GoIter { >, fn_name: &str, ) -> BackendResult>> { - let next = match next_fn { - Some(f) => f, - None => { - let result = Err(BackendError::unknown(format!( - "iterator vtable function '{fn_name}' not set" - ))); - return (result, GasInfo::free()); - } + let next = if let Some(f) = next_fn { + f + } else { + let result = Err(BackendError::unknown(format!( + "iterator vtable function '{fn_name}' not set" + ))); + return (result, GasInfo::free()); }; let mut output = UnmanagedVector::default(); diff --git a/libwasmvm/src/storage.rs b/libwasmvm/src/storage.rs index cb751c7cf..22dbb7134 100644 --- a/libwasmvm/src/storage.rs +++ b/libwasmvm/src/storage.rs @@ -104,41 +104,38 @@ impl Storage for GoStorage { } fn next(&mut self, iterator_id: u32) -> BackendResult> { - let iterator = match self.iterators.get_mut(&iterator_id) { - Some(i) => i, - None => { - return ( - Err(BackendError::iterator_does_not_exist(iterator_id)), - GasInfo::free(), - ) - } + let iterator = if let Some(i) = self.iterators.get_mut(&iterator_id) { + i + } else { + return ( + Err(BackendError::iterator_does_not_exist(iterator_id)), + GasInfo::free(), + ); }; iterator.next() } fn next_key(&mut self, iterator_id: u32) -> BackendResult>> { - let iterator = match self.iterators.get_mut(&iterator_id) { - Some(i) => i, - None => { - return ( - Err(BackendError::iterator_does_not_exist(iterator_id)), - GasInfo::free(), - ) - } + let iterator = if let Some(i) = self.iterators.get_mut(&iterator_id) { + i + } else { + return ( + Err(BackendError::iterator_does_not_exist(iterator_id)), + GasInfo::free(), + ); }; iterator.next_key() } fn next_value(&mut self, iterator_id: u32) -> BackendResult>> { - let iterator = match self.iterators.get_mut(&iterator_id) { - Some(i) => i, - None => { - return ( - Err(BackendError::iterator_does_not_exist(iterator_id)), - GasInfo::free(), - ) - } + let iterator = if let Some(i) = self.iterators.get_mut(&iterator_id) { + i + } else { + return ( + Err(BackendError::iterator_does_not_exist(iterator_id)), + GasInfo::free(), + ); }; iterator.next_value()