From b3222276abea45deaf5be7bcbd875f32a7de06a6 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 18 Jul 2022 18:21:14 +0200 Subject: [PATCH] Improve 'board::BitboardIterator' * Accurate 'size_hint'. * Exact size. * Fused iterator (keeps returning 'None' after returning 'None' once). --- src/board/bitboard/iterator.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/board/bitboard/iterator.rs b/src/board/bitboard/iterator.rs index 06db283..fcd644c 100644 --- a/src/board/bitboard/iterator.rs +++ b/src/board/bitboard/iterator.rs @@ -14,4 +14,14 @@ impl Iterator for BitboardIterator { Some(crate::board::Square::from_index(lsb)) } } + + fn size_hint(&self) -> (usize, Option) { + let size = self.0.count_ones() as usize; + + (size, Some(size)) + } } + +impl ExactSizeIterator for BitboardIterator {} + +impl std::iter::FusedIterator for BitboardIterator {}