[−][src]Trait pyo3::prelude::AsPyRef
Retrieves &'py types from Py<T> or PyObject.
Examples
PyObject::as_ref returns &PyAny.
use pyo3::ObjectProtocol; let obj: PyObject = { let gil = Python::acquire_gil(); let py = gil.python(); py.eval("[]", None, None).unwrap().to_object(py) }; let gil = Python::acquire_gil(); let py = gil.python(); assert_eq!(obj.as_ref(py).len().unwrap(), 0); // PyAny implements ObjectProtocol
Py<T>::as_ref returns &PyDict, &PyList or so for native types, and &PyCell<T>
for #[pyclass].
use pyo3::ObjectProtocol; let obj: PyObject = { let gil = Python::acquire_gil(); let py = gil.python(); py.eval("[]", None, None).unwrap().to_object(py) }; let gil = Python::acquire_gil(); let py = gil.python(); assert_eq!(obj.as_ref(py).len().unwrap(), 0); // PyAny implements ObjectProtocol
Associated Types
type Target
Required methods
Loading content...Implementors
impl AsPyRef for PyObject[src]
impl<T> AsPyRef for Py<T> where
T: PyTypeInfo, [src]
T: PyTypeInfo,