[−][src]Trait pyo3::AsPyRef
Retrieves &'py types from Py<T> or PyObject.
Examples
PyObject::as_ref returns &PyAny.
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);
Py<T>::as_ref returns &PyDict, &PyList or so for native types, and &PyCell<T>
for #[pyclass].
#[pyclass] struct Counter { count: usize, } let counter = { let gil = Python::acquire_gil(); let py = gil.python(); Py::new(py, Counter { count: 0}).unwrap() }; let gil = Python::acquire_gil(); let py = gil.python(); let counter_cell: &PyCell<Counter> = counter.as_ref(py); let counter_ref = counter_cell.borrow(); assert_eq!(counter_ref.count, 0);
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,