mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
PyIter::iter
This commit is contained in:
@@ -51,14 +51,11 @@ impl<T> ArgIterable<T> {
|
||||
/// This operation may fail if an exception is raised while invoking the
|
||||
/// `__iter__` method of the iterable object.
|
||||
pub fn iter<'a>(&self, vm: &'a VirtualMachine) -> PyResult<PyIterIter<'a, T>> {
|
||||
let iter_obj = match self.iterfn {
|
||||
let iter = PyIter::new(match self.iterfn {
|
||||
Some(f) => f(self.iterable.clone(), vm)?,
|
||||
None => PySequenceIterator::new(self.iterable.clone()).into_object(vm),
|
||||
};
|
||||
|
||||
let length_hint = vm.length_hint(iter_obj.clone())?;
|
||||
|
||||
Ok(PyIterIter::new(vm, PyIter::new(iter_obj), length_hint))
|
||||
});
|
||||
iter.iter(vm)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,16 @@ where
|
||||
};
|
||||
iternext(self.0.borrow(), vm)
|
||||
}
|
||||
|
||||
pub fn iter<'a, U>(&self, vm: &'a VirtualMachine) -> PyResult<PyIterIter<'a, U>> {
|
||||
let obj = self.as_object();
|
||||
let length_hint = vm.length_hint(obj.clone())?;
|
||||
Ok(PyIterIter::new(
|
||||
vm,
|
||||
PyIter::<PyObjectRef>::new(obj.clone()),
|
||||
length_hint,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Borrow<PyObjectRef> for PyIter<T>
|
||||
|
||||
Reference in New Issue
Block a user