MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / from_object

Method from_object

src/objects/iterator.rs:36–49  ·  view source on GitHub ↗

Constructs a PyIterator from a Python iterator object.

(
        py: Python<'p>,
        obj: PyObject,
    )

Source from the content-addressed store, hash-verified

34impl<'p> PyIterator<'p> {
35 /// Constructs a PyIterator from a Python iterator object.
36 pub fn from_object(
37 py: Python<'p>,
38 obj: PyObject,
39 ) -> Result<PyIterator<'p>, PythonObjectDowncastError<'p>> {
40 if unsafe { ffi::PyIter_Check(obj.as_ptr()) != 0 } {
41 Ok(PyIterator { py, iter: obj })
42 } else {
43 Err(PythonObjectDowncastError::new(
44 py,
45 "PyIterator",
46 obj.get_type(py),
47 ))
48 }
49 }
50
51 /// Gets the Python iterator object.
52 #[inline]

Callers

nothing calls this directly

Calls 3

PyIter_CheckFunction · 0.50
as_ptrMethod · 0.45
get_typeMethod · 0.45

Tested by

no test coverage detected