[−][src]Struct pyo3::prelude::PyObject
A python object
The python object's lifetime is managed by python's garbage collector.
Technically, it is a safe wrapper around NonNull<ffi::PyObject>
.
Methods
impl PyObject
[src]
pub unsafe fn from_owned_ptr(_py: Python, ptr: *mut PyObject) -> PyObject
[src]
Creates a PyObject
instance for the given FFI pointer.
This moves ownership over the pointer into the PyObject
.
Undefined behavior if the pointer is NULL or invalid.
pub unsafe fn from_owned_ptr_or_panic(
_py: Python,
ptr: *mut PyObject
) -> PyObject
[src]
_py: Python,
ptr: *mut PyObject
) -> PyObject
Creates a PyObject
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<PyObject>
[src]
py: Python,
ptr: *mut PyObject
) -> PyResult<PyObject>
Construct PyObject
from the result of a Python FFI call that
returns a new reference (owned pointer).
Returns Err(PyErr)
if the pointer is null
.
pub unsafe fn from_owned_ptr_or_opt(
_py: Python,
ptr: *mut PyObject
) -> Option<PyObject>
[src]
_py: Python,
ptr: *mut PyObject
) -> Option<PyObject>
Construct PyObject
from the result of a Python FFI call that
returns a new reference (owned pointer).
Returns None
if the pointer is null
.
pub unsafe fn from_borrowed_ptr(_py: Python, ptr: *mut PyObject) -> PyObject
[src]
Creates a PyObject
instance for the given Python FFI pointer.
Calls Py_INCREF() on the ptr.
Undefined behavior if the pointer is NULL or invalid.
pub unsafe fn from_borrowed_ptr_or_err(
py: Python,
ptr: *mut PyObject
) -> PyResult<PyObject>
[src]
py: Python,
ptr: *mut PyObject
) -> PyResult<PyObject>
Creates a PyObject
instance for the given Python FFI pointer.
Calls Py_INCREF() on the ptr.
Returns Err(PyErr)
if the pointer is null
.
pub unsafe fn from_borrowed_ptr_or_opt(
py: Python,
ptr: *mut PyObject
) -> Option<PyObject>
[src]
py: Python,
ptr: *mut PyObject
) -> Option<PyObject>
Creates a PyObject
instance for the given Python FFI pointer.
Calls Py_INCREF() on the ptr.
Returns None
if the pointer is null
.
pub fn get_refcnt(&self) -> isize
[src]
Gets the reference count of the ffi::PyObject pointer.
pub fn clone_ref(&self, py: Python) -> Self
[src]
Clone self, Calls Py_INCREF() on the ptr.
pub fn is_none(&self) -> bool
[src]
Returns whether the object is considered to be None. This is equivalent to the Python expression: 'is None'
pub fn is_true(&self, py: Python) -> PyResult<bool>
[src]
Returns whether the object is considered to be true. This is equivalent to the Python expression: 'not not self'
pub fn cast_as<D>(&self, py: Python) -> Result<&D, PyDowncastError> where
D: for<'v> PyTryFrom<'v>,
[src]
D: for<'v> PyTryFrom<'v>,
Casts the PyObject to a concrete Python object type.
pub fn extract<'p, D>(&'p self, py: Python) -> PyResult<D> where
D: FromPyObject<'p>,
[src]
D: FromPyObject<'p>,
Extracts some type from the Python object.
This is a wrapper function around FromPyObject::extract()
.
pub fn getattr<N>(&self, py: Python, attr_name: N) -> PyResult<PyObject> where
N: ToPyObject,
[src]
N: ToPyObject,
Retrieves an attribute value. This is equivalent to the Python expression 'self.attr_name'.
pub fn call(
&self,
py: Python,
args: impl IntoPy<Py<PyTuple>>,
kwargs: Option<&PyDict>
) -> PyResult<PyObject>
[src]
&self,
py: Python,
args: impl IntoPy<Py<PyTuple>>,
kwargs: Option<&PyDict>
) -> PyResult<PyObject>
Calls the object. This is equivalent to the Python expression: 'self(*args, **kwargs)'
pub fn call0(&self, py: Python) -> PyResult<PyObject>
[src]
Calls the object without arguments. This is equivalent to the Python expression: 'self()'
pub fn call1(
&self,
py: Python,
args: impl IntoPy<Py<PyTuple>>
) -> PyResult<PyObject>
[src]
&self,
py: Python,
args: impl IntoPy<Py<PyTuple>>
) -> PyResult<PyObject>
Calls the object. This is equivalent to the Python expression: 'self(*args)'
pub fn call_method(
&self,
py: Python,
name: &str,
args: impl IntoPy<Py<PyTuple>>,
kwargs: Option<&PyDict>
) -> PyResult<PyObject>
[src]
&self,
py: Python,
name: &str,
args: impl IntoPy<Py<PyTuple>>,
kwargs: Option<&PyDict>
) -> PyResult<PyObject>
Calls a method on the object. This is equivalent to the Python expression: 'self.name(*args, **kwargs)'
pub fn call_method0(&self, py: Python, name: &str) -> PyResult<PyObject>
[src]
Calls a method on the object. This is equivalent to the Python expression: 'self.name()'
pub fn call_method1(
&self,
py: Python,
name: &str,
args: impl IntoPy<Py<PyTuple>>
) -> PyResult<PyObject>
[src]
&self,
py: Python,
name: &str,
args: impl IntoPy<Py<PyTuple>>
) -> PyResult<PyObject>
Calls a method on the object. This is equivalent to the Python expression: 'self.name(*args)'
Trait Implementations
impl AsPyPointer for PyObject
[src]
impl IntoPyPointer for PyObject
[src]
#[must_use]
fn into_ptr(self) -> *mut PyObject
[src]
Gets the underlying FFI pointer, returns a owned pointer.
impl ToPyObject for PyObject
[src]
impl IntoPyObject for PyObject
[src]
fn into_object(self, _py: Python) -> PyObject
[src]
impl<'a> FromPyObject<'a> for PyObject
[src]
impl AsPyRef<PyAny> for PyObject
[src]
fn as_ref(&self, _py: Python) -> PyRef<PyAny>
[src]
fn as_mut(&mut self, _py: Python) -> PyRefMut<PyAny>
[src]
fn with<F, R>(&self, f: F) -> R where
F: FnOnce(Python, PyRef<T>) -> R,
[src]
F: FnOnce(Python, PyRef<T>) -> R,
Acquire python gil and call closure with object reference.
fn with_mut<F, R>(&mut self, f: F) -> R where
F: FnOnce(Python, PyRefMut<T>) -> R,
[src]
F: FnOnce(Python, PyRefMut<T>) -> R,
Acquire python gil and call closure with mutable object reference.
fn into_py<F, R>(self, f: F) -> R where
Self: IntoPyPointer,
F: FnOnce(Python, PyRef<T>) -> R,
[src]
Self: IntoPyPointer,
F: FnOnce(Python, PyRef<T>) -> R,
fn into_mut_py<F, R>(self, f: F) -> R where
Self: IntoPyPointer,
F: FnOnce(Python, PyRefMut<T>) -> R,
[src]
Self: IntoPyPointer,
F: FnOnce(Python, PyRefMut<T>) -> R,
impl<T> From<Py<T>> for PyObject
[src]
impl<'a, T> From<&'a T> for PyObject where
T: AsPyPointer,
[src]
T: AsPyPointer,
impl<'a, T> From<&'a mut T> for PyObject where
T: AsPyPointer,
[src]
T: AsPyPointer,
impl PartialEq<PyObject> for PyObject
[src]
fn eq(&self, o: &PyObject) -> bool
[src]
Checks for identity, not python's __eq__
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl Sync for PyObject
[src]
impl Send for PyObject
[src]
impl Drop for PyObject
[src]
Dropping a PyObject
instance decrements the reference count on the object by 1.
impl Debug for PyObject
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,