[−][src]Struct pyo3::Py
A Python object of known type.
Accessing this object is thread-safe, since any access to its API requires a
Python<'py> GIL token.
See the guide for an explanation of the different Python object types.
Technically, it is a safe wrapper around NonNull<ffi::PyObject> with
specified type information.
Implementations
impl<T> Py<T> where
T: PyClass, [src]
T: PyClass,
pub fn new(
py: Python<'_>,
value: impl Into<PyClassInitializer<T>>
) -> PyResult<Py<T>> where
T::BaseLayout: PyBorrowFlagLayout<T::BaseType>, [src]
py: Python<'_>,
value: impl Into<PyClassInitializer<T>>
) -> PyResult<Py<T>> where
T::BaseLayout: PyBorrowFlagLayout<T::BaseType>,
Create a new instance Py<T> of a #[pyclass] on the Python heap.
pub fn borrow<'py>(&'py self, py: Python<'py>) -> PyRef<'py, T>[src]
Immutably borrows the value T. This borrow lasts untill the returned PyRef exists.
Equivalent to self.as_ref(py).borrow() -
see PyCell::borrow
Panics
Panics if the value is currently mutably borrowed. For a non-panicking variant, use
try_borrow.
pub fn borrow_mut<'py>(&'py self, py: Python<'py>) -> PyRefMut<'py, T>[src]
Mutably borrows the value T. This borrow lasts untill the returned PyRefMut exists.
Equivalent to self.as_ref(py).borrow_mut() -
see PyCell::borrow_mut
Panics
Panics if the value is currently mutably borrowed. For a non-panicking variant, use
try_borrow_mut.
pub fn try_borrow<'py>(
&'py self,
py: Python<'py>
) -> Result<PyRef<'py, T>, PyBorrowError>[src]
&'py self,
py: Python<'py>
) -> Result<PyRef<'py, T>, PyBorrowError>
Immutably borrows the value T, returning an error if the value is currently
mutably borrowed. This borrow lasts untill the returned PyRef exists.
This is the non-panicking variant of borrow.
Equivalent to self.as_ref(py).try_borrow() -
see PyCell::try_borrow
pub fn try_borrow_mut<'py>(
&'py self,
py: Python<'py>
) -> Result<PyRefMut<'py, T>, PyBorrowMutError>[src]
&'py self,
py: Python<'py>
) -> Result<PyRefMut<'py, T>, PyBorrowMutError>
Mutably borrows the value T, returning an error if the value is currently borrowed.
This borrow lasts untill the returned PyRefMut exists.
This is the non-panicking variant of borrow_mut.
Equivalent to self.as_ref(py).try_borrow_mut() - see [PyCell::try_borrow_mut`](../pycell/struct.PyCell.html#method.try_borrow_mut)
impl<T> Py<T>[src]
pub unsafe fn from_owned_ptr(_py: Python<'_>, 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(
_py: Python<'_>,
ptr: *mut PyObject
) -> Py<T>[src]
_py: Python<'_>,
ptr: *mut PyObject
) -> Py<T>
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]
py: Python<'_>,
ptr: *mut PyObject
) -> PyResult<Py<T>>
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(_py: Python<'_>, 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, _py: Python<'_>) -> isize[src]
Gets the reference count of the ffi::PyObject pointer.
pub fn clone_ref(&self, py: Python<'_>) -> Py<T>[src]
Clones self by calling Py_INCREF() on the ptr.
Trait Implementations
impl<T> AsPyPointer for Py<T>[src]
impl<T> AsPyRef for Py<T> where
T: PyTypeInfo, [src]
T: PyTypeInfo,
impl<T> Clone for Py<T>[src]
fn clone(&self) -> Self[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl<T: Debug> Debug 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<'a, T, '_> From<&'_ PyCell<T>> for Py<T> where
T: PyClass, [src]
T: PyClass,
impl<'a, T> From<&'a T> for Py<T> where
T: AsPyPointer + PyNativeType, [src]
T: AsPyPointer + PyNativeType,
impl<T> From<Py<T>> for PyObject[src]
impl<'a, T> From<PyRef<'a, T>> for Py<T> where
T: PyClass, [src]
T: PyClass,
impl<'a, T> From<PyRefMut<'a, T>> for Py<T> where
T: PyClass, [src]
T: PyClass,
impl<'a> FromPy<&'a PyTuple> for Py<PyTuple>[src]
impl FromPy<()> for Py<PyTuple>[src]
Converts () to an empty Python tuple.
impl<'a, T> FromPyObject<'a> for Py<T> where
T: PyTypeInfo,
&'a T::AsRefTarget: FromPyObject<'a>,
T::AsRefTarget: 'a + AsPyPointer, [src]
T: PyTypeInfo,
&'a T::AsRefTarget: FromPyObject<'a>,
T::AsRefTarget: 'a + AsPyPointer,
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<T> IntoPy<PyObject> for Py<T>[src]
fn into_py(self, _py: Python<'_>) -> PyObject[src]
Converts a Py instance to PyObject.
Consumes self without calling Py_DECREF().
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> PartialEq<Py<T>> for Py<T>[src]
impl<T> Send for Py<T>[src]
impl<T> Sync for Py<T>[src]
impl<T> ToPyObject for Py<T>[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Py<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Unpin for Py<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Py<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T> FromPy<T> for T[src]
impl<'a, T> FromPyObject<'a> for T where
T: PyClass + Clone, [src]
T: PyClass + Clone,
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> IntoPy<U> for T where
U: FromPy<T>, [src]
U: FromPy<T>,
impl<T> ToBorrowedObject for T where
T: ToPyObject, [src]
T: ToPyObject,
fn with_borrowed_ptr<F, R>(&self, py: Python<'_>, f: F) -> R where
F: FnOnce(*mut PyObject) -> R, [src]
F: FnOnce(*mut PyObject) -> R,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T[src]
fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,