[][src]Struct pyo3::Py

#[repr(transparent)]
pub struct Py<T>(_, _);

Safe wrapper around unsafe *mut ffi::PyObject pointer with specified type information.

Py<T> is thread-safe, because any python related operations require a Python<'p> token.

Methods

impl<T> Py<T>[src]

pub fn new(py: Python, value: T) -> PyResult<Py<T>> where
    T: PyTypeCreate
[src]

Create new instance of T and move it under python management

pub unsafe fn from_owned_ptr(ptr: *mut PyObject) -> Py<T>[src]

Creates a Py<T> instance for the given FFI pointer. This moves ownership over the pointer into the Py<T>. Undefined behavior if the pointer is NULL or invalid.

pub unsafe fn from_owned_ptr_or_panic(ptr: *mut PyObject) -> Py<T>[src]

Creates a Py<T> instance for the given FFI pointer. Panics if the pointer is null. Undefined behavior if the pointer is invalid.

pub unsafe fn from_owned_ptr_or_err(
    py: Python,
    ptr: *mut PyObject
) -> PyResult<Py<T>>
[src]

Construct Py<T> from the result of a Python FFI call that returns a new reference (owned pointer). Returns Err(PyErr) if the pointer is null. Unsafe because the pointer might be invalid.

pub unsafe fn from_borrowed_ptr(ptr: *mut PyObject) -> Py<T>[src]

Creates a Py<T> instance for the given Python FFI pointer. Calls Py_INCREF() on the ptr. Undefined behavior if the pointer is NULL or invalid.

pub fn get_refcnt(&self) -> isize[src]

Gets the reference count of the ffi::PyObject pointer.

pub fn clone_ref(&self, _py: Python) -> Py<T>[src]

Clone self, Calls Py_INCREF() on the ptr.

Trait Implementations

impl<T> AsPyPointer for Py<T>[src]

fn as_ptr(&self) -> *mut PyObject[src]

Gets the underlying FFI pointer, returns a borrowed pointer.

impl<T> IntoPyPointer for Py<T>[src]

#[must_use] fn into_ptr(self) -> *mut PyObject[src]

Gets the underlying FFI pointer, returns a owned pointer.

impl<T> ToPyObject for Py<T>[src]

fn to_object(&self, py: Python) -> PyObject[src]

Converts Py instance -> PyObject.

impl FromPy<()> for Py<PyTuple>[src]

Converts () to an empty Python tuple.

impl<'a> FromPy<&'a PyTuple> for Py<PyTuple>[src]

impl<T> IntoPy<PyObject> for Py<T>[src]

fn into_py(self, py: Python) -> PyObject[src]

Converts Py instance -> PyObject. Consumes self without calling Py_DECREF()

impl<A: IntoPy<PyObject>> IntoPy<Py<PyTuple>> for (A,)[src]

impl<A: IntoPy<PyObject>, B: IntoPy<PyObject>> IntoPy<Py<PyTuple>> for (A, B)[src]

impl<A: IntoPy<PyObject>, B: IntoPy<PyObject>, C: IntoPy<PyObject>> IntoPy<Py<PyTuple>> for (A, B, C)[src]

impl<A: IntoPy<PyObject>, B: IntoPy<PyObject>, C: IntoPy<PyObject>, D: IntoPy<PyObject>> IntoPy<Py<PyTuple>> for (A, B, C, D)[src]

impl<A: IntoPy<PyObject>, B: IntoPy<PyObject>, C: IntoPy<PyObject>, D: IntoPy<PyObject>, E: IntoPy<PyObject>> IntoPy<Py<PyTuple>> for (A, B, C, D, E)[src]

impl<A: IntoPy<PyObject>, B: IntoPy<PyObject>, C: IntoPy<PyObject>, D: IntoPy<PyObject>, E: IntoPy<PyObject>, F: IntoPy<PyObject>> IntoPy<Py<PyTuple>> for (A, B, C, D, E, F)[src]

impl<A: IntoPy<PyObject>, B: IntoPy<PyObject>, C: IntoPy<PyObject>, D: IntoPy<PyObject>, E: IntoPy<PyObject>, F: IntoPy<PyObject>, G: IntoPy<PyObject>> IntoPy<Py<PyTuple>> for (A, B, C, D, E, F, G)[src]

impl<A: IntoPy<PyObject>, B: IntoPy<PyObject>, C: IntoPy<PyObject>, D: IntoPy<PyObject>, E: IntoPy<PyObject>, F: IntoPy<PyObject>, G: IntoPy<PyObject>, H: IntoPy<PyObject>> IntoPy<Py<PyTuple>> for (A, B, C, D, E, F, G, H)[src]

impl<A: IntoPy<PyObject>, B: IntoPy<PyObject>, C: IntoPy<PyObject>, D: IntoPy<PyObject>, E: IntoPy<PyObject>, F: IntoPy<PyObject>, G: IntoPy<PyObject>, H: IntoPy<PyObject>, I: IntoPy<PyObject>> IntoPy<Py<PyTuple>> for (A, B, C, D, E, F, G, H, I)[src]

impl<'a, T> FromPyObject<'a> for Py<T> where
    T: AsPyPointer,
    &'a T: 'a + FromPyObject<'a>, 
[src]

fn extract(ob: &'a PyAny) -> PyResult<Self>[src]

Extracts Self from the source PyObject.

impl<T> AsPyRef<T> for Py<T> where
    T: PyTypeInfo
[src]

impl<T> Send for Py<T>[src]

impl<T> Sync for Py<T>[src]

impl<T> Drop for Py<T>[src]

Dropping a Py instance decrements the reference count on the object by 1.

impl<T> From<Py<T>> for PyObject[src]

impl<'a, T> From<PyRef<'a, T>> for Py<T> where
    T: PyTypeInfo
[src]

impl<'a, T> From<PyRefMut<'a, T>> for Py<T> where
    T: PyTypeInfo
[src]

impl<T> PartialEq<Py<T>> for Py<T>[src]

impl<T: Debug> Debug for Py<T>[src]

Auto Trait Implementations

impl<T> Unpin for Py<T> where
    T: Unpin

impl<T> UnwindSafe for Py<T> where
    T: UnwindSafe

impl<T> RefUnwindSafe for Py<T> where
    T: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]