[−][src]Struct numpy::array::PyArray
A safe, static-typed interface for NumPy ndarray.
Memory location
- Case1: Constructed via
IntoPyArrayorfrom_vecorfrom_owned_array.
These methods don't allocate memory and use Box<[T]> as a internal buffer.
Please take care that you cannot use some destructive methods like resize,
for this kind of array.
- Case2: Constructed via other methods, like
ToPyArrayorfrom_sliceorfrom_array.
These methods allocate memory in Python's private heap.
In both cases, PyArray is managed by Python GC. So you can neither retrieve it nor deallocate it manually.
Reference
Like new, all constractor methods of PyArray returns &PyArray.
This design follows pyo3's ownership concept.
Data type and Dimension
PyArray has 2 type parametes T and D. T represents its data type like
f32, and D represents its dimension.
All data types you can use implements TypeNum.
Dimensions are represented by ndarray's Dimension trait.
Typically, you can use Ix1, Ix2, .. for fixed size arrays, and use IxDyn for dynamic
dimensioned arrays. They're re-exported from ndarray crate.
You can also use various type aliases we provide, like PyArray1
or PyArrayDyn.
To specify concrete dimension like 3×4×5, you can use types which implements ndarray's
IntoDimension
trait. Typically, you can use array(e.g. [3, 4, 5]) or tuple(e.g. (3, 4, 5)) as a dimension.
Example
use pyo3::{GILGuard, Python}; use numpy::PyArray; use ndarray::Array; let gil = Python::acquire_gil(); let pyarray = PyArray::arange(gil.python(), 0., 4., 1.).reshape([2, 2]).unwrap(); let array = array![[3., 4.], [5., 6.]]; assert_eq!( array.dot(&pyarray.as_array()), array![[8., 15.], [12., 23.]] );
Methods
impl<T, D> PyArray<T, D>[src]
pub fn as_array_ptr(&self) -> *mut PyArrayObject[src]
Gets a raw PyArrayObject pointer.
pub fn is_contiguous(&self) -> bool[src]
Returns true if the internal data of the array is C-style contiguous
(default of numpy and ndarray) or Fortran-style contiguous.
Example
use pyo3::types::IntoPyDict; let gil = pyo3::Python::acquire_gil(); let py = gil.python(); let array = numpy::PyArray::arange(py, 0, 1, 10); assert!(array.is_contiguous()); let locals = [("np", numpy::get_array_module(py).unwrap())].into_py_dict(py); let not_contiguous: &numpy::PyArray1<f32> = py .eval("np.zeros((3, 5))[::2, 4]", Some(locals), None) .unwrap() .downcast() .unwrap(); assert!(!not_contiguous.is_contiguous());
pub fn is_fotran_contiguous(&self) -> bool[src]
Returns true if the internal data of the array is Fortran-style contiguous.
pub fn is_c_contiguous(&self) -> bool[src]
Returns true if the internal data of the array is C-style contiguous.
pub fn to_owned(&self) -> Py<Self>[src]
Get Py<PyArray> from &PyArray, which is the owned wrapper of PyObject.
You can use this method when you have to avoid lifetime annotation to your function args
or return types, like used with pyo3's pymethod.
Example
use pyo3::{GILGuard, Python, Py, AsPyRef}; use numpy::PyArray1; fn return_py_array() -> Py<PyArray1<i32>> { let gil = Python::acquire_gil(); let array = PyArray1::zeros(gil.python(), [5], false); array.to_owned() } let gil = Python::acquire_gil(); let array = return_py_array(); assert_eq!(array.as_ref(gil.python()).as_slice().unwrap(), &[0, 0, 0, 0, 0]);
pub unsafe fn from_owned_ptr(py: Python, ptr: *mut PyObject) -> &Self[src]
Constructs PyArray from raw python object without incrementing reference counts.
pub unsafe fn from_borrowed_ptr(py: Python, ptr: *mut PyObject) -> &Self[src]
Constructs PyArray from raw python object and increments reference counts.
pub fn ndim(&self) -> usize[src]
Returns the number of dimensions in the array.
Same as numpy.ndarray.ndim
Example
use numpy::PyArray3; let gil = pyo3::Python::acquire_gil(); let arr = PyArray3::<f64>::new(gil.python(), [4, 5, 6], false); assert_eq!(arr.ndim(), 3);
pub fn strides(&self) -> &[isize][src]
Returns a slice which contains how many bytes you need to jump to the next row.
Same as numpy.ndarray.strides
Example
use numpy::PyArray3; let gil = pyo3::Python::acquire_gil(); let arr = PyArray3::<f64>::new(gil.python(), [4, 5, 6], false); assert_eq!(arr.strides(), &[240, 48, 8]);
pub fn shape(&self) -> &[usize][src]
Returns a slice which contains dimmensions of the array.
Same as numpy.ndarray.shape
Example
use numpy::PyArray3; let gil = pyo3::Python::acquire_gil(); let arr = PyArray3::<f64>::new(gil.python(), [4, 5, 6], false); assert_eq!(arr.shape(), &[4, 5, 6]);
pub fn len(&self) -> usize[src]
Calcurates the total number of elements in the array.
impl<T: TypeNum, D: Dimension> PyArray<T, D>[src]
pub fn dims(&self) -> D[src]
Same as shape, but returns D
pub fn new<'py, ID>(py: Python<'py>, dims: ID, is_fortran: bool) -> &'py Self where
ID: IntoDimension<Dim = D>, [src]
ID: IntoDimension<Dim = D>,
Creates a new uninitialized PyArray in python heap.
If is_fortran == true, returns Fortran-order array. Else, returns C-order array.
Example
use numpy::PyArray3; let gil = pyo3::Python::acquire_gil(); let pyarray = PyArray3::<i32>::new(gil.python(), [4, 5, 6], false); assert_eq!(pyarray.shape(), &[4, 5, 6]);
pub fn zeros<'py, ID>(py: Python<'py>, dims: ID, is_fortran: bool) -> &'py Self where
ID: IntoDimension<Dim = D>, [src]
ID: IntoDimension<Dim = D>,
Construct a new nd-dimensional array filled with 0.
If is_fortran is true, then
a fortran order array is created, otherwise a C-order array is created.
See also PyArray_Zeros
Example
use numpy::PyArray2; let gil = pyo3::Python::acquire_gil(); let pyarray: &PyArray2<usize> = PyArray2::zeros(gil.python(), [2, 2], false); assert_eq!(pyarray.as_array(), array![[0, 0], [0, 0]]);
pub fn as_slice(&self) -> Result<&[T], ErrorKind>[src]
Get the immutable view of the internal data of PyArray, as slice.
Returns ErrorKind::NotContiguous if the internal array is not contiguous.
Example
use numpy::{PyArray, PyArray1}; use pyo3::types::IntoPyDict; let gil = pyo3::Python::acquire_gil(); let py = gil.python(); let py_array = PyArray::arange(py, 0, 4, 1).reshape([2, 2]).unwrap(); assert_eq!(py_array.as_slice().unwrap(), &[0, 1, 2, 3]); let locals = [("np", numpy::get_array_module(py).unwrap())].into_py_dict(py); let not_contiguous: &PyArray1<f32> = py .eval("np.zeros((3, 5))[[0, 2], [3, 4]]", Some(locals), None) .unwrap() .downcast() .unwrap(); assert!(not_contiguous.as_slice().is_err());
pub fn as_slice_mut(&self) -> Result<&mut [T], ErrorKind>[src]
Get the mmutable view of the internal data of PyArray, as slice.
pub fn from_array<'py, S>(py: Python<'py>, arr: &ArrayBase<S, D>) -> &'py Self where
S: Data<Elem = T>, [src]
S: Data<Elem = T>,
Construct PyArray from ndarray::ArrayBase.
This method allocates memory in Python's heap via numpy api, and then copies all elements of the array there.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let pyarray = PyArray::from_array(gil.python(), &array![[1, 2], [3, 4]]); assert_eq!(pyarray.as_array(), array![[1, 2], [3, 4]]);
pub fn from_owned_array<'py>(py: Python<'py>, arr: Array<T, D>) -> &'py Self[src]
Construct PyArray from
ndarray::Array.
This method uses internal Vec
of ndarray::Array as numpy array.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let pyarray = PyArray::from_owned_array(gil.python(), array![[1, 2], [3, 4]]); assert_eq!(pyarray.as_array(), array![[1, 2], [3, 4]]);
pub fn as_array(&self) -> ArrayView<T, D>[src]
Get the immutable view of the internal data of PyArray, as
ndarray::ArrayView.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let py_array = PyArray::arange(gil.python(), 0, 4, 1).reshape([2, 2]).unwrap(); assert_eq!( py_array.as_array(), array![[0, 1], [2, 3]] )
pub fn as_array_mut(&self) -> ArrayViewMut<T, D>[src]
Almost same as as_array, but returns ArrayViewMut.
pub fn get<Idx>(&self, index: Idx) -> Option<&T> where
Idx: NpyIndex<Dim = D>, [src]
Idx: NpyIndex<Dim = D>,
Get an immutable reference of a specified element, with checking the passed index is valid.
See NpyIndex for what types you can use as index.
If you pass an invalid index to this function, it returns None.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let arr = PyArray::arange(gil.python(), 0, 16, 1).reshape([2, 2, 4]).unwrap(); assert_eq!(*arr.get([1, 0, 3]).unwrap(), 11); assert!(arr.get([2, 0, 3]).is_none());
For fixed dimension arrays, passing an index with invalid dimension causes compile error.
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let arr = PyArray::arange(gil.python(), 0, 16, 1).reshape([2, 2, 4]).unwrap(); let a = arr.get([1, 2]); // Compile Error!
However, for dinamic arrays, we cannot raise a compile error and just returns None.
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let arr = PyArray::arange(gil.python(), 0, 16, 1).reshape([2, 2, 4]).unwrap(); let arr = arr.into_dyn(); assert!(arr.get([1, 2].as_ref()).is_none());
pub fn get_mut<Idx>(&self, index: Idx) -> Option<&mut T> where
Idx: NpyIndex<Dim = D>, [src]
Idx: NpyIndex<Dim = D>,
Same as get, but returns Option<&mut T>.
pub unsafe fn uget<Idx>(&self, index: Idx) -> &T where
Idx: NpyIndex<Dim = D>, [src]
Idx: NpyIndex<Dim = D>,
Get an immutable reference of a specified element, without checking the passed index is valid.
See NpyIndex for what types you can use as index.
Passing an invalid index can cause undefined behavior(mostly SIGSEGV).
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let arr = PyArray::arange(gil.python(), 0, 16, 1).reshape([2, 2, 4]).unwrap(); assert_eq!(unsafe { *arr.uget([1, 0, 3]) }, 11);
pub unsafe fn uget_mut<Idx>(&self, index: Idx) -> &mut T where
Idx: NpyIndex<Dim = D>, [src]
Idx: NpyIndex<Dim = D>,
Same as uget, but returns &mut T.
pub fn into_dyn(&self) -> &PyArray<T, IxDyn>[src]
Get dynamic dimensioned array from fixed dimension array.
See get for usage.
impl<T: TypeNum + Clone, D: Dimension> PyArray<T, D>[src]
pub fn to_owned_array(&self) -> Array<T, D>[src]
Get a copy of PyArray as
ndarray::Array.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let py_array = PyArray::arange(gil.python(), 0, 4, 1).reshape([2, 2]).unwrap(); assert_eq!( py_array.to_owned_array(), array![[0, 1], [2, 3]] )
impl<T: TypeNum> PyArray<T, Ix1>[src]
pub fn from_slice<'py>(py: Python<'py>, slice: &[T]) -> &'py Self[src]
Construct one-dimension PyArray from slice.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let array = [1, 2, 3, 4, 5]; let pyarray = PyArray::from_slice(gil.python(), &array); assert_eq!(pyarray.as_slice().unwrap(), &[1, 2, 3, 4, 5]);
pub fn from_vec<'py>(py: Python<'py>, vec: Vec<T>) -> &'py Self[src]
Construct one-dimension PyArray
from Vec.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let vec = vec![1, 2, 3, 4, 5]; let pyarray = PyArray::from_vec(gil.python(), vec); assert_eq!(pyarray.as_slice().unwrap(), &[1, 2, 3, 4, 5]);
pub fn from_exact_iter(
py: Python,
iter: impl ExactSizeIterator<Item = T>
) -> &Self[src]
py: Python,
iter: impl ExactSizeIterator<Item = T>
) -> &Self
Construct one-dimension PyArray from a type which implements
ExactSizeIterator.
Example
use numpy::PyArray; use std::collections::BTreeSet; let gil = pyo3::Python::acquire_gil(); let vec = vec![1, 2, 3, 4, 5]; let pyarray = PyArray::from_iter(gil.python(), vec.iter().map(|&x| x)); assert_eq!(pyarray.as_slice().unwrap(), &[1, 2, 3, 4, 5]);
pub fn from_iter(py: Python, iter: impl IntoIterator<Item = T>) -> &Self[src]
Construct one-dimension PyArray from a type which implements
IntoIterator.
If no reliable size_hint is available,
this method can allocate memory multiple time, which can hurt performance.
Example
use numpy::PyArray; use std::collections::BTreeSet; let gil = pyo3::Python::acquire_gil(); let set: BTreeSet<u32> = [4, 3, 2, 5, 1].into_iter().cloned().collect(); let pyarray = PyArray::from_iter(gil.python(), set); assert_eq!(pyarray.as_slice().unwrap(), &[1, 2, 3, 4, 5]);
pub fn resize(&self, new_elems: usize) -> Result<(), ErrorKind>[src]
Extends or trancates the length of 1 dimension PyArray.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let pyarray = PyArray::arange(gil.python(), 0, 10, 1); assert_eq!(pyarray.len(), 10); pyarray.resize(100).unwrap(); assert_eq!(pyarray.len(), 100);
impl<T: TypeNum> PyArray<T, Ix2>[src]
pub fn from_vec2<'py>(
py: Python<'py>,
v: &Vec<Vec<T>>
) -> Result<&'py Self, ErrorKind> where
T: Clone, [src]
py: Python<'py>,
v: &Vec<Vec<T>>
) -> Result<&'py Self, ErrorKind> where
T: Clone,
Construct a two-dimension PyArray from Vec<Vec<T>>.
This function checks all dimension of inner vec, and if there's any vec
where its dimension differs from others, it returns ArrayCastError.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let vec2 = vec![vec![1, 2, 3]; 2]; let pyarray = PyArray::from_vec2(gil.python(), &vec2).unwrap(); assert_eq!(pyarray.as_array(), array![[1, 2, 3], [1, 2, 3]]); assert!(PyArray::from_vec2(gil.python(), &vec![vec![1], vec![2, 3]]).is_err());
impl<T: TypeNum> PyArray<T, Ix3>[src]
pub fn from_vec3<'py>(
py: Python<'py>,
v: &Vec<Vec<Vec<T>>>
) -> Result<&'py Self, ErrorKind> where
T: Clone, [src]
py: Python<'py>,
v: &Vec<Vec<Vec<T>>>
) -> Result<&'py Self, ErrorKind> where
T: Clone,
Construct a three-dimension PyArray from Vec<Vec<Vec<T>>>.
This function checks all dimension of inner vec, and if there's any vec where its dimension differs from others, it returns error.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let vec2 = vec![vec![vec![1, 2]; 2]; 2]; let pyarray = PyArray::from_vec3(gil.python(), &vec2).unwrap(); assert_eq!( pyarray.as_array(), array![[[1, 2], [1, 2]], [[1, 2], [1, 2]]] ); assert!(PyArray::from_vec3(gil.python(), &vec![vec![vec![1], vec![]]]).is_err());
impl<T: TypeNum, D> PyArray<T, D>[src]
pub fn data_type(&self) -> NpyDataType[src]
Returns the scalar type of the array.
pub fn copy_to<U: TypeNum>(
&self,
other: &PyArray<U, D>
) -> Result<(), ErrorKind>[src]
&self,
other: &PyArray<U, D>
) -> Result<(), ErrorKind>
Copies self into other, performing a data-type conversion if necessary.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let pyarray_f = PyArray::arange(gil.python(), 2.0, 5.0, 1.0); let pyarray_i = PyArray::<i64, _>::new(gil.python(), [3], false); assert!(pyarray_f.copy_to(pyarray_i).is_ok()); assert_eq!(pyarray_i.as_slice().unwrap(), &[2, 3, 4]);
pub fn cast<'py, U: TypeNum>(
&'py self,
is_fortran: bool
) -> Result<&'py PyArray<U, D>, ErrorKind>[src]
&'py self,
is_fortran: bool
) -> Result<&'py PyArray<U, D>, ErrorKind>
Cast the PyArray<T> to PyArray<U>, by allocating a new array.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let pyarray_f = PyArray::arange(gil.python(), 2.0, 5.0, 1.0); let pyarray_i = pyarray_f.cast::<i32>(false).unwrap(); assert_eq!(pyarray_i.as_slice().unwrap(), &[2, 3, 4]);
pub fn reshape<'py, ID, D2>(
&'py self,
dims: ID
) -> Result<&'py PyArray<T, D2>, ErrorKind> where
ID: IntoDimension<Dim = D2>,
D2: Dimension, [src]
&'py self,
dims: ID
) -> Result<&'py PyArray<T, D2>, ErrorKind> where
ID: IntoDimension<Dim = D2>,
D2: Dimension,
Construct a new array which has same values as self, same matrix order, but has different
dimensions specified by dims.
Since a returned array can contain a same pointer as self, we highly recommend to drop an
old array, if this method returns Ok.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let array = PyArray::from_exact_iter(gil.python(), 0..9); let array = array.reshape([3, 3]).unwrap(); assert_eq!(array.as_array(), array![[0, 1, 2], [3, 4, 5], [6, 7, 8]]); assert!(array.reshape([5]).is_err());
pub fn reshape_with_order<'py, ID, D2>(
&'py self,
dims: ID,
order: NPY_ORDER
) -> Result<&'py PyArray<T, D2>, ErrorKind> where
ID: IntoDimension<Dim = D2>,
D2: Dimension, [src]
&'py self,
dims: ID,
order: NPY_ORDER
) -> Result<&'py PyArray<T, D2>, ErrorKind> where
ID: IntoDimension<Dim = D2>,
D2: Dimension,
Same as reshape, but you can change the order of returned matrix.
impl<T: TypeNum + AsPrimitive<f64>> PyArray<T, Ix1>[src]
pub fn arange<'py>(py: Python<'py>, start: T, stop: T, step: T) -> &'py Self[src]
Return evenly spaced values within a given interval. Same as numpy.arange.
See also PyArray_Arange.
Example
use numpy::PyArray; let gil = pyo3::Python::acquire_gil(); let pyarray = PyArray::arange(gil.python(), 2.0, 4.0, 0.5); assert_eq!(pyarray.as_slice().unwrap(), &[2.0, 2.5, 3.0, 3.5]); let pyarray = PyArray::arange(gil.python(), -2, 4, 3); assert_eq!(pyarray.as_slice().unwrap(), &[-2, 1]);
Trait Implementations
impl<T, D> AsPyPointer for PyArray<T, D>[src]
impl<T, D> AsRef<PyAny> for PyArray<T, D>[src]
impl<T, D> Debug for PyArray<T, D>[src]
impl<T, D> Display for PyArray<T, D>[src]
impl<'a, T, D> From<&'a PyArray<T, D>> for &'a PyAny[src]
impl<'a, T: TypeNum, D: Dimension> FromPyObject<'a> for &'a PyArray<T, D>[src]
impl<T, D> IntoPy<PyObject> for PyArray<T, D>[src]
impl<T, D> PartialEq<PyArray<T, D>> for PyArray<T, D>[src]
impl<T, D> PyLayout<PyArray<T, D>> for PyArrayObject[src]
const IS_NATIVE_TYPE: bool[src]
fn get_super(&mut self) -> Option<&mut <T as PyTypeInfo>::BaseLayout>[src]
unsafe fn py_init(&mut self, _value: T)[src]
unsafe fn py_drop(&mut self, _py: Python)[src]
impl<T, D> PyNativeType for PyArray<T, D>[src]
impl<T, D> PySizedLayout<PyArray<T, D>> for PyArrayObject[src]
impl<T, D> PyTypeInfo for PyArray<T, D>[src]
type Type = ()
Type of objects to store in PyObject struct
type BaseType = PyAny
Base class
type Layout = PyArrayObject
Layout
type BaseLayout = PyObject
Layout of Basetype.
type Initializer = PyNativeTypeInitializer<Self>
Initializer for layout
type AsRefTarget = Self
Utility type to make AsPyRef work
const NAME: &'static str[src]
const MODULE: Option<&'static str>[src]
fn type_object() -> &'static PyTypeObject[src]
fn is_instance(ptr: &PyAny) -> bool[src]
const DESCRIPTION: &'static str[src]
const FLAGS: usize[src]
fn is_exact_instance(object: &PyAny) -> bool[src]
impl<T, D> ToPyObject for PyArray<T, D>[src]
Auto Trait Implementations
impl<T, D> RefUnwindSafe for PyArray<T, D> where
D: RefUnwindSafe,
T: RefUnwindSafe,
D: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, D> Send for PyArray<T, D> where
D: Send,
T: Send,
D: Send,
T: Send,
impl<T, D> Sync for PyArray<T, D> where
D: Sync,
T: Sync,
D: Sync,
T: Sync,
impl<T, D> Unpin for PyArray<T, D> where
D: Unpin,
T: Unpin,
D: Unpin,
T: Unpin,
impl<T, D> UnwindSafe for PyArray<T, D> where
D: UnwindSafe,
T: UnwindSafe,
D: 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<'p, T> FromPyPointer<'p> for T where
T: 'p + PyNativeType, [src]
T: 'p + PyNativeType,
unsafe fn from_owned_ptr_or_opt(
py: Python<'p>,
ptr: *mut PyObject
) -> Option<&'p T>[src]
py: Python<'p>,
ptr: *mut PyObject
) -> Option<&'p T>
unsafe fn from_borrowed_ptr_or_opt(
py: Python<'p>,
ptr: *mut PyObject
) -> Option<&'p T>[src]
py: Python<'p>,
ptr: *mut PyObject
) -> Option<&'p T>
unsafe fn from_owned_ptr_or_panic(
py: Python<'p>,
ptr: *mut PyObject
) -> &'p Self[src]
py: Python<'p>,
ptr: *mut PyObject
) -> &'p Self
unsafe fn from_owned_ptr(py: Python<'p>, ptr: *mut PyObject) -> &'p Self[src]
unsafe fn from_owned_ptr_or_err(
py: Python<'p>,
ptr: *mut PyObject
) -> Result<&'p Self, PyErr>[src]
py: Python<'p>,
ptr: *mut PyObject
) -> Result<&'p Self, PyErr>
unsafe fn from_borrowed_ptr_or_panic(
py: Python<'p>,
ptr: *mut PyObject
) -> &'p Self[src]
py: Python<'p>,
ptr: *mut PyObject
) -> &'p Self
unsafe fn from_borrowed_ptr(py: Python<'p>, ptr: *mut PyObject) -> &'p Self[src]
unsafe fn from_borrowed_ptr_or_err(
py: Python<'p>,
ptr: *mut PyObject
) -> Result<&'p Self, PyErr>[src]
py: Python<'p>,
ptr: *mut PyObject
) -> Result<&'p Self, PyErr>
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> ObjectProtocol for T where
T: PyNativeType + AsPyPointer, [src]
T: PyNativeType + AsPyPointer,
fn hasattr<N>(&self, attr_name: N) -> Result<bool, PyErr> where
N: ToPyObject, [src]
N: ToPyObject,
fn getattr<N>(&self, attr_name: N) -> Result<&PyAny, PyErr> where
N: ToPyObject, [src]
N: ToPyObject,
fn setattr<N, V>(&self, attr_name: N, value: V) -> Result<(), PyErr> where
N: ToBorrowedObject,
V: ToBorrowedObject, [src]
N: ToBorrowedObject,
V: ToBorrowedObject,
fn delattr<N>(&self, attr_name: N) -> Result<(), PyErr> where
N: ToPyObject, [src]
N: ToPyObject,
fn compare<O>(&self, other: O) -> Result<Ordering, PyErr> where
O: ToPyObject, [src]
O: ToPyObject,
fn rich_compare<O>(
&self,
other: O,
compare_op: CompareOp
) -> Result<PyObject, PyErr> where
O: ToPyObject, [src]
&self,
other: O,
compare_op: CompareOp
) -> Result<PyObject, PyErr> where
O: ToPyObject,
fn repr(&self) -> Result<&PyString, PyErr>[src]
fn str(&self) -> Result<&PyString, PyErr>[src]
fn is_callable(&self) -> bool[src]
fn call(
&self,
args: impl IntoPy<Py<PyTuple>>,
kwargs: Option<&PyDict>
) -> Result<&PyAny, PyErr>[src]
&self,
args: impl IntoPy<Py<PyTuple>>,
kwargs: Option<&PyDict>
) -> Result<&PyAny, PyErr>
fn call0(&self) -> Result<&PyAny, PyErr>[src]
fn call1(&self, args: impl IntoPy<Py<PyTuple>>) -> Result<&PyAny, PyErr>[src]
fn call_method(
&self,
name: &str,
args: impl IntoPy<Py<PyTuple>>,
kwargs: Option<&PyDict>
) -> Result<&PyAny, PyErr>[src]
&self,
name: &str,
args: impl IntoPy<Py<PyTuple>>,
kwargs: Option<&PyDict>
) -> Result<&PyAny, PyErr>
fn call_method0(&self, name: &str) -> Result<&PyAny, PyErr>[src]
fn call_method1(
&self,
name: &str,
args: impl IntoPy<Py<PyTuple>>
) -> Result<&PyAny, PyErr>[src]
&self,
name: &str,
args: impl IntoPy<Py<PyTuple>>
) -> Result<&PyAny, PyErr>
fn hash(&self) -> Result<isize, PyErr>[src]
fn is_true(&self) -> Result<bool, PyErr>[src]
fn is_none(&self) -> bool[src]
fn len(&self) -> Result<usize, PyErr>[src]
fn is_empty(&self) -> Result<bool, PyErr>[src]
fn get_item<K>(&self, key: K) -> Result<&PyAny, PyErr> where
K: ToBorrowedObject, [src]
K: ToBorrowedObject,
fn set_item<K, V>(&self, key: K, value: V) -> Result<(), PyErr> where
K: ToBorrowedObject,
V: ToBorrowedObject, [src]
K: ToBorrowedObject,
V: ToBorrowedObject,
fn del_item<K>(&self, key: K) -> Result<(), PyErr> where
K: ToBorrowedObject, [src]
K: ToBorrowedObject,
fn iter(&self) -> Result<PyIterator, PyErr>[src]
fn get_type(&self) -> &PyType[src]
fn get_type_ptr(&self) -> *mut PyTypeObject[src]
fn cast_as<'a, D>(&'a self) -> Result<&'a D, PyDowncastError> where
D: PyTryFrom<'a>,
&'a PyAny: From<&'a T>, [src]
D: PyTryFrom<'a>,
&'a PyAny: From<&'a T>,
fn extract<'a, D>(&'a self) -> Result<D, PyErr> where
D: FromPyObject<'a>,
&'a PyAny: From<&'a T>, [src]
D: FromPyObject<'a>,
&'a PyAny: From<&'a T>,
fn get_refcnt(&self) -> isize[src]
fn None(&self) -> PyObject[src]
impl<'py, T> PyDowncastImpl for T where
T: 'py + PyNativeType, [src]
T: 'py + PyNativeType,
unsafe fn unchecked_downcast(obj: &PyAny) -> &T[src]
fn __private__(&self) -> PrivateMarker[src]
impl<'v, T> PyTryFrom<'v> for T where
T: PyDowncastImpl + PyTypeInfo + PyNativeType, [src]
T: PyDowncastImpl + PyTypeInfo + PyNativeType,
fn try_from<V>(value: V) -> Result<&'v T, PyDowncastError> where
V: Into<&'v PyAny>, [src]
V: Into<&'v PyAny>,
fn try_from_exact<V>(value: V) -> Result<&'v T, PyDowncastError> where
V: Into<&'v PyAny>, [src]
V: Into<&'v PyAny>,
unsafe fn try_from_unchecked<V>(value: V) -> &'v T where
V: Into<&'v PyAny>, [src]
V: Into<&'v PyAny>,
impl<T> PyTypeObject for T where
T: PyTypeInfo, [src]
T: PyTypeInfo,
fn type_object() -> Py<PyType>[src]
impl<T> ToBorrowedObject for T where
T: ToPyObject, [src]
T: ToPyObject,
default 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> ToBorrowedObject for T where
T: ToPyObject + AsPyPointer, [src]
T: ToPyObject + AsPyPointer,
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> ToString for T where
T: Display + ?Sized, [src]
T: Display + ?Sized,
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>,