forked from Rust-related/RustPython
Add size_hint() to PyIterator
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user