From 490c638b4f168535c4efcca04c92366ee36ea727 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Tue, 9 Jun 2020 15:47:27 -0500 Subject: [PATCH] Add size_hint() to PyIterator --- vm/src/pyobject.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vm/src/pyobject.rs b/vm/src/pyobject.rs index 5d43fdf5c..4f82b554d 100644 --- a/vm/src/pyobject.rs +++ b/vm/src/pyobject.rs @@ -980,9 +980,12 @@ impl PyIterable { }, )?; + 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 PyIterable { pub struct PyIterator<'a, T> { vm: &'a VirtualMachine, obj: PyObjectRef, + lenhint: Option, _item: std::marker::PhantomData, } @@ -1012,6 +1016,10 @@ where } } } + + fn size_hint(&self) -> (usize, Option) { + (self.lenhint.unwrap_or(0), self.lenhint) + } } impl TryFromObject for PyIterable