From 2852a896657275b3f812ced9a8945b743a94e3d7 Mon Sep 17 00:00:00 2001 From: AsukaMinato Date: Wed, 8 Nov 2023 15:32:48 +0900 Subject: [PATCH] let-else --- src/batch_shuffle.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/batch_shuffle.rs b/src/batch_shuffle.rs index d9502c1e..8ba83c49 100644 --- a/src/batch_shuffle.rs +++ b/src/batch_shuffle.rs @@ -69,11 +69,10 @@ where I: Clone + Send + Sync, { fn get(&self, index: usize) -> Option { - if let Some(index) = self.indices.get(index) { - self.dataset.get(*index) - } else { - None - } + let Some(index) = self.indices.get(index) else { + return None; + }; + self.dataset.get(*index) } fn len(&self) -> usize { @@ -247,11 +246,11 @@ impl Iterator for BatchShuffledDataloaderIterator { } } - if let Some(items) = self.strategy.batch(true) { - return Some(self.batcher.batch(items)); - } + let Some(items) = self.strategy.batch(true) else { + return None; + }; - None + Some(self.batcher.batch(items)) } }