From e16eaeaa11c4119543bfcb5e61f74fcde780727a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 10 Dec 2020 11:22:20 +0100 Subject: [PATCH] Implement size_hint on the GroupBy and GroupByMut Iterators --- library/core/src/slice/iter.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index 8f52fa852ba9..730009568dd3 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -3009,6 +3009,15 @@ where P: FnMut(&T, &T) -> bool, Some(head) } } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + if self.slice.is_empty() { + (0, Some(0)) + } else { + (1, Some(self.slice.len())) + } + } } #[unstable(feature = "slice_group_by", issue = "0")] @@ -3080,6 +3089,15 @@ where P: FnMut(&T, &T) -> bool, Some(head) } } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + if self.slice.is_empty() { + (0, Some(0)) + } else { + (1, Some(self.slice.len())) + } + } } #[unstable(feature = "slice_group_by", issue = "0")]