Add size_hint() to PyIterator

This commit is contained in:
Noah
2020-06-09 15:47:27 -05:00
committed by Jeong YunWon
parent 50770f5155
commit 490c638b4f

View File

@@ -980,9 +980,12 @@ impl<T> PyIterable<T> {
},
)?;
let lenhint = objiter::length_hint(vm, iter_obj.clone())?;
Ok(PyIterator {
vm,
obj: iter_obj,
lenhint,
_item: std::marker::PhantomData,
})
}
@@ -991,6 +994,7 @@ impl<T> PyIterable<T> {
pub struct PyIterator<'a, T> {
vm: &'a VirtualMachine,
obj: PyObjectRef,
lenhint: Option<usize>,
_item: std::marker::PhantomData<T>,
}
@@ -1012,6 +1016,10 @@ where
}
}
}
fn size_hint(&self) -> (usize, Option<usize>) {
(self.lenhint.unwrap_or(0), self.lenhint)
}
}
impl<T> TryFromObject for PyIterable<T>