Impl ExactSizeIterator for IdxRange

This commit is contained in:
oxalica 2023-05-06 21:15:49 +08:00
parent a4966c9282
commit 300f3a1b43

View File

@ -176,9 +176,14 @@ pub fn end(&self) -> Idx<T> {
impl<T> Iterator for IdxRange<T> { impl<T> Iterator for IdxRange<T> {
type Item = Idx<T>; type Item = Idx<T>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.range.next().map(|raw| Idx::from_raw(raw.into())) self.range.next().map(|raw| Idx::from_raw(raw.into()))
} }
fn size_hint(&self) -> (usize, Option<usize>) {
self.range.size_hint()
}
} }
impl<T> DoubleEndedIterator for IdxRange<T> { impl<T> DoubleEndedIterator for IdxRange<T> {
@ -187,6 +192,8 @@ fn next_back(&mut self) -> Option<Self::Item> {
} }
} }
impl<T> ExactSizeIterator for IdxRange<T> {}
impl<T> fmt::Debug for IdxRange<T> { impl<T> fmt::Debug for IdxRange<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple(&format!("IdxRange::<{}>", std::any::type_name::<T>())) f.debug_tuple(&format!("IdxRange::<{}>", std::any::type_name::<T>()))