Skip to content

Commit

Permalink
Use let-else
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Aug 28, 2023
1 parent 65cfd95 commit ca676ed
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
8 changes: 2 additions & 6 deletions libwasmvm/src/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ impl GoIter {
}

pub fn next(&mut self) -> BackendResult<Option<Record>> {
let next = if let Some(f) = self.vtable.next {
f
} else {
let Some(next) = self.vtable.next else {
let result = Err(BackendError::unknown(
"iterator vtable function 'next' not set",
));
Expand Down Expand Up @@ -139,9 +137,7 @@ impl GoIter {
>,
fn_name: &str,
) -> BackendResult<Option<Vec<u8>>> {
let next = if let Some(f) = next_fn {
f
} else {
let Some(next) = next_fn else {
let result = Err(BackendError::unknown(format!(
"iterator vtable function '{fn_name}' not set"
)));
Expand Down
12 changes: 3 additions & 9 deletions libwasmvm/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ impl Storage for GoStorage {
}

fn next(&mut self, iterator_id: u32) -> BackendResult<Option<Record>> {
let iterator = if let Some(i) = self.iterators.get_mut(&iterator_id) {
i
} else {
let Some(iterator) = self.iterators.get_mut(&iterator_id) else {
return (
Err(BackendError::iterator_does_not_exist(iterator_id)),
GasInfo::free(),
Expand All @@ -116,9 +114,7 @@ impl Storage for GoStorage {
}

fn next_key(&mut self, iterator_id: u32) -> BackendResult<Option<Vec<u8>>> {
let iterator = if let Some(i) = self.iterators.get_mut(&iterator_id) {
i
} else {
let Some(iterator) = self.iterators.get_mut(&iterator_id) else {
return (
Err(BackendError::iterator_does_not_exist(iterator_id)),
GasInfo::free(),
Expand All @@ -129,9 +125,7 @@ impl Storage for GoStorage {
}

fn next_value(&mut self, iterator_id: u32) -> BackendResult<Option<Vec<u8>>> {
let iterator = if let Some(i) = self.iterators.get_mut(&iterator_id) {
i
} else {
let Some(iterator) = self.iterators.get_mut(&iterator_id) else {
return (
Err(BackendError::iterator_does_not_exist(iterator_id)),
GasInfo::free(),
Expand Down

0 comments on commit ca676ed

Please sign in to comment.