Struct pyo3::Bound

source ·
pub struct Bound<'py, T>(/* private fields */);
Expand description

A GIL-attached equivalent to Py.

Implementations§

source§

impl<'py, T> Bound<'py, T>
where T: PyClass,

source

pub fn new( py: Python<'py>, value: impl Into<PyClassInitializer<T>> ) -> PyResult<Bound<'py, T>>

Creates a new instance Bound<T> of a #[pyclass] on the Python heap.

§Examples
use pyo3::prelude::*;

#[pyclass]
struct Foo {/* fields omitted */}

Python::with_gil(|py| -> PyResult<Py<Foo>> {
    let foo: Bound<'_, Foo> = Bound::new(py, Foo {})?;
    Ok(foo.into())
})?;
source§

impl<'py> Bound<'py, PyAny>

source

pub unsafe fn from_owned_ptr(py: Python<'py>, ptr: *mut PyObject) -> Self

Constructs a new Bound<'py, PyAny> from a pointer. Panics if ptr is null.

§Safety
  • ptr must be a valid pointer to a Python object
  • ptr must be an owned Python reference, as the Bound<'py, PyAny> will assume ownership
source

pub unsafe fn from_owned_ptr_or_opt( py: Python<'py>, ptr: *mut PyObject ) -> Option<Self>

Constructs a new Bound<'py, PyAny> from a pointer. Returns None if ptr is null.

§Safety
  • ptr must be a valid pointer to a Python object, or null
  • ptr must be an owned Python reference, as the Bound<'py, PyAny> will assume ownership
source

pub unsafe fn from_owned_ptr_or_err( py: Python<'py>, ptr: *mut PyObject ) -> PyResult<Self>

Constructs a new Bound<'py, PyAny> from a pointer. Returns an Err by calling PyErr::fetch if ptr is null.

§Safety
  • ptr must be a valid pointer to a Python object, or null
  • ptr must be an owned Python reference, as the Bound<'py, PyAny> will assume ownership
source

pub unsafe fn from_borrowed_ptr(py: Python<'py>, ptr: *mut PyObject) -> Self

Constructs a new Bound<'py, PyAny> from a pointer by creating a new Python reference. Panics if ptr is null.

§Safety
  • ptr must be a valid pointer to a Python object
source

pub unsafe fn from_borrowed_ptr_or_opt( py: Python<'py>, ptr: *mut PyObject ) -> Option<Self>

Constructs a new Bound<'py, PyAny> from a pointer by creating a new Python reference. Returns None if ptr is null.

§Safety
  • ptr must be a valid pointer to a Python object, or null
source

pub unsafe fn from_borrowed_ptr_or_err( py: Python<'py>, ptr: *mut PyObject ) -> PyResult<Self>

Constructs a new Bound<'py, PyAny> from a pointer by creating a new Python reference. Returns an Err by calling PyErr::fetch if ptr is null.

§Safety
  • ptr must be a valid pointer to a Python object, or null
source§

impl<'py, T> Bound<'py, T>
where T: PyClass,

source

pub fn borrow(&self) -> PyRef<'py, T>

Immutably borrows the value T.

This borrow lasts while the returned PyRef exists. Multiple immutable borrows can be taken out at the same time.

For frozen classes, the simpler get is available.

§Examples
#[pyclass]
struct Foo {
    inner: u8,
}

Python::with_gil(|py| -> PyResult<()> {
    let foo: Bound<'_, Foo> = Bound::new(py, Foo { inner: 73 })?;
    let inner: &u8 = &foo.borrow().inner;

    assert_eq!(*inner, 73);
    Ok(())
})?;
§Panics

Panics if the value is currently mutably borrowed. For a non-panicking variant, use try_borrow.

source

pub fn borrow_mut(&self) -> PyRefMut<'py, T>
where T: PyClass<Frozen = False>,

Mutably borrows the value T.

This borrow lasts while the returned PyRefMut exists.

§Examples
#[pyclass]
struct Foo {
    inner: u8,
}

Python::with_gil(|py| -> PyResult<()> {
    let foo: Bound<'_, Foo> = Bound::new(py, Foo { inner: 73 })?;
    foo.borrow_mut().inner = 35;

    assert_eq!(foo.borrow().inner, 35);
    Ok(())
})?;
§Panics

Panics if the value is currently borrowed. For a non-panicking variant, use try_borrow_mut.

source

pub fn try_borrow(&self) -> Result<PyRef<'py, T>, PyBorrowError>

Attempts to immutably borrow the value T, returning an error if the value is currently mutably borrowed.

The borrow lasts while the returned PyRef exists.

This is the non-panicking variant of borrow.

For frozen classes, the simpler get is available.

source

pub fn try_borrow_mut(&self) -> Result<PyRefMut<'py, T>, PyBorrowMutError>
where T: PyClass<Frozen = False>,

Attempts to mutably borrow the value T, returning an error if the value is currently borrowed.

The borrow lasts while the returned PyRefMut exists.

This is the non-panicking variant of borrow_mut.

source

pub fn get(&self) -> &T
where T: PyClass<Frozen = True> + Sync,

Provide an immutable borrow of the value T without acquiring the GIL.

This is available if the class is frozen and Sync.

§Examples
use std::sync::atomic::{AtomicUsize, Ordering};

#[pyclass(frozen)]
struct FrozenCounter {
    value: AtomicUsize,
}

Python::with_gil(|py| {
    let counter = FrozenCounter { value: AtomicUsize::new(0) };

    let py_counter = Bound::new(py, counter).unwrap();

    py_counter.get().value.fetch_add(1, Ordering::Relaxed);
});
source§

impl<'py, T> Bound<'py, T>

source

pub fn py(&self) -> Python<'py>

Returns the GIL token associated with this object.

source

pub fn as_ptr(&self) -> *mut PyObject

Returns the raw FFI pointer represented by self.

§Safety

Callers are responsible for ensuring that the pointer does not outlive self.

The reference is borrowed; callers should not decrease the reference count when they are finished with the pointer.

source

pub fn into_ptr(self) -> *mut PyObject

Returns an owned raw FFI pointer represented by self.

§Safety

The reference is owned; when finished the caller should either transfer ownership of the pointer or decrease the reference count (e.g. with pyo3::ffi::Py_DecRef).

source

pub fn as_any(&self) -> &Bound<'py, PyAny>

Helper to cast to Bound<'py, PyAny>.

source

pub fn into_any(self) -> Bound<'py, PyAny>

Helper to cast to Bound<'py, PyAny>, transferring ownership.

source

pub fn as_borrowed<'a>(&'a self) -> Borrowed<'a, 'py, T>

Casts this Bound<T> to a Borrowed<T> smart pointer.

source

pub fn unbind(self) -> Py<T>

Removes the connection for this Bound<T> from the GIL, allowing it to cross thread boundaries.

source

pub fn as_unbound(&self) -> &Py<T>

Removes the connection for this Bound<T> from the GIL, allowing it to cross thread boundaries, without transferring ownership.

source

pub fn as_gil_ref(&'py self) -> &'py T::AsRefTarget
where T: HasPyGilRef,

Casts this Bound<T> as the corresponding “GIL Ref” type.

This is a helper to be used for migration from the deprecated “GIL Refs” API.

source

pub fn into_gil_ref(self) -> &'py T::AsRefTarget
where T: HasPyGilRef,

Casts this Bound<T> as the corresponding “GIL Ref” type, registering the pointer on the release pool.

This is a helper to be used for migration from the deprecated “GIL Refs” API.

Trait Implementations§

source§

impl<'py> Add<&Bound<'py, PyComplex>> for Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the + operator.
source§

fn add(self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the + operation. Read more
source§

impl<'py> Add<Bound<'py, PyComplex>> for &Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the + operator.
source§

fn add(self, other: Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the + operation. Read more
source§

impl<'py> Add for &Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the + operator.
source§

fn add(self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the + operation. Read more
source§

impl<'py> Add for Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the + operator.
source§

fn add(self, other: Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the + operation. Read more
source§

impl<T> AsPyPointer for Bound<'_, T>

source§

fn as_ptr(&self) -> *mut PyObject

Returns the underlying FFI pointer as a borrowed pointer.
source§

impl<'py, T> AsRef<Bound<'py, PyAny>> for Bound<'py, T>

source§

fn as_ref(&self) -> &Bound<'py, PyAny>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T> Clone for Bound<'_, T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'py, T> Debug for Bound<'py, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'py, T> Deref for Bound<'py, T>
where T: DerefToPyAny,

§

type Target = Bound<'py, PyAny>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Bound<'py, PyAny>

Dereferences the value.
source§

impl<'py, T> Display for Bound<'py, T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'py> Div<&Bound<'py, PyComplex>> for Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the / operator.
source§

fn div(self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the / operation. Read more
source§

impl<'py> Div<Bound<'py, PyComplex>> for &Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the / operator.
source§

fn div(self, other: Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the / operation. Read more
source§

impl<'py> Div for &Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the / operator.
source§

fn div(self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the / operation. Read more
source§

impl<'py> Div for Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the / operator.
source§

fn div(self, other: Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the / operation. Read more
source§

impl<T> Drop for Bound<'_, T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, 'py, T> From<&'a Bound<'py, T>> for Borrowed<'a, 'py, T>

source§

fn from(instance: &'a Bound<'py, T>) -> Self

Create borrow on a Bound

source§

impl From<Bound<'_, PyByteArray>> for PyBackedBytes

source§

fn from(py_bytearray: Bound<'_, PyByteArray>) -> Self

Converts to this type from the input type.
source§

impl From<Bound<'_, PyBytes>> for PyBackedBytes

source§

fn from(py_bytes: Bound<'_, PyBytes>) -> Self

Converts to this type from the input type.
source§

impl<T> From<Bound<'_, T>> for PyObject
where T: AsRef<PyAny>,

source§

fn from(other: Bound<'_, T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<Bound<'_, T>> for Py<T>

source§

fn from(other: Bound<'_, T>) -> Self

Converts to this type from the input type.
source§

impl<'py, T> From<Bound<'py, T>> for PyErr
where T: ToPyErr,

source§

fn from(err: Bound<'py, T>) -> PyErr

Converts to this type from the input type.
source§

impl<'py, T> FromPyObject<'py> for Bound<'py, T>
where T: PyTypeCheck,

source§

fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self>

Extracts Self from the source PyObject.

source§

fn extract(ob: &'py PyAny) -> PyResult<Self>

Extracts Self from the source GIL Ref obj. Read more
source§

fn type_input() -> TypeInfo

Extracts the type hint information for this type when it appears as an argument. Read more
source§

impl<I: SliceIndex<[u8]>> Index<I> for Bound<'_, PyBytes>

This is the same way Vec is indexed.

§

type Output = <I as SliceIndex<[u8]>>::Output

The returned type after indexing.
source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<'py> IntoIterator for &Bound<'py, PyDict>

§

type Item = (Bound<'py, PyAny>, Bound<'py, PyAny>)

The type of the elements being iterated over.
§

type IntoIter = BoundDictIterator<'py>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'py> IntoIterator for &Bound<'py, PyFrozenSet>

source§

fn into_iter(self) -> Self::IntoIter

Returns an iterator of values in this set.

§

type Item = Bound<'py, PyAny>

The type of the elements being iterated over.
§

type IntoIter = BoundFrozenSetIterator<'py>

Which kind of iterator are we turning this into?
source§

impl<'py> IntoIterator for &Bound<'py, PyIterator>

§

type Item = Result<Bound<'py, PyAny>, PyErr>

The type of the elements being iterated over.
§

type IntoIter = Bound<'py, PyIterator>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'py> IntoIterator for &Bound<'py, PyList>

§

type Item = Bound<'py, PyAny>

The type of the elements being iterated over.
§

type IntoIter = BoundListIterator<'py>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'py> IntoIterator for &Bound<'py, PySet>

source§

fn into_iter(self) -> Self::IntoIter

Returns an iterator of values in this set.

§Panics

If PyO3 detects that the set is mutated during iteration, it will panic.

§

type Item = Bound<'py, PyAny>

The type of the elements being iterated over.
§

type IntoIter = BoundSetIterator<'py>

Which kind of iterator are we turning this into?
source§

impl<'py> IntoIterator for &Bound<'py, PyTuple>

§

type Item = Bound<'py, PyAny>

The type of the elements being iterated over.
§

type IntoIter = BoundTupleIterator<'py>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'py> IntoIterator for Bound<'py, PyDict>

§

type Item = (Bound<'py, PyAny>, Bound<'py, PyAny>)

The type of the elements being iterated over.
§

type IntoIter = BoundDictIterator<'py>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'py> IntoIterator for Bound<'py, PyFrozenSet>

source§

fn into_iter(self) -> Self::IntoIter

Returns an iterator of values in this set.

§

type Item = Bound<'py, PyAny>

The type of the elements being iterated over.
§

type IntoIter = BoundFrozenSetIterator<'py>

Which kind of iterator are we turning this into?
source§

impl<'py> IntoIterator for Bound<'py, PyList>

§

type Item = Bound<'py, PyAny>

The type of the elements being iterated over.
§

type IntoIter = BoundListIterator<'py>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'py> IntoIterator for Bound<'py, PySet>

source§

fn into_iter(self) -> Self::IntoIter

Returns an iterator of values in this set.

§Panics

If PyO3 detects that the set is mutated during iteration, it will panic.

§

type Item = Bound<'py, PyAny>

The type of the elements being iterated over.
§

type IntoIter = BoundSetIterator<'py>

Which kind of iterator are we turning this into?
source§

impl<'py> IntoIterator for Bound<'py, PyTuple>

§

type Item = Bound<'py, PyAny>

The type of the elements being iterated over.
§

type IntoIter = BoundTupleIterator<'py>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<T> IntoPy<Py<PyAny>> for &Bound<'_, T>

source§

fn into_py(self, py: Python<'_>) -> PyObject

Converts &Bound instance -> PyObject, increasing the reference count.

source§

fn type_output() -> TypeInfo

Extracts the type hint information for this type when it appears as a return value. Read more
source§

impl<T> IntoPy<Py<PyAny>> for Bound<'_, T>

source§

fn into_py(self, _py: Python<'_>) -> PyObject

Converts a Bound instance to PyObject.

source§

fn type_output() -> TypeInfo

Extracts the type hint information for this type when it appears as a return value. Read more
source§

impl IntoPy<Py<PyString>> for &Bound<'_, PyString>

source§

fn into_py(self, _py: Python<'_>) -> Py<PyString>

Performs the conversion.
source§

fn type_output() -> TypeInfo

Extracts the type hint information for this type when it appears as a return value. Read more
source§

impl IntoPy<Py<PyString>> for Bound<'_, PyString>

source§

fn into_py(self, _py: Python<'_>) -> Py<PyString>

Performs the conversion.
source§

fn type_output() -> TypeInfo

Extracts the type hint information for this type when it appears as a return value. Read more
source§

impl IntoPy<Py<PyTuple>> for &Bound<'_, PyTuple>

source§

fn into_py(self, _: Python<'_>) -> Py<PyTuple>

Performs the conversion.
source§

fn type_output() -> TypeInfo

Extracts the type hint information for this type when it appears as a return value. Read more
source§

impl IntoPy<Py<PyTuple>> for Bound<'_, PyTuple>

source§

fn into_py(self, _: Python<'_>) -> Py<PyTuple>

Performs the conversion.
source§

fn type_output() -> TypeInfo

Extracts the type hint information for this type when it appears as a return value. Read more
source§

impl<'py> Iterator for Bound<'py, PyIterator>

source§

fn next(&mut self) -> Option<Self::Item>

Retrieves the next item from an iterator.

Returns None when the iterator is exhausted. If an exception occurs, returns Some(Err(..)). Further next() calls after an exception occurs are likely to repeatedly result in the same exception.

§

type Item = Result<Bound<'py, PyAny>, PyErr>

The type of the elements being iterated over.
source§

fn size_hint(&self) -> (usize, Option<usize>)

Returns the bounds on the remaining length of the iterator. Read more
source§

fn next_chunk<const N: usize>( &mut self ) -> Result<[Self::Item; N], IntoIter<Self::Item, N>>
where Self: Sized,

🔬This is a nightly-only experimental API. (iter_next_chunk)
Advances the iterator and returns an array containing the next N values. Read more
1.0.0 · source§

fn count(self) -> usize
where Self: Sized,

Consumes the iterator, counting the number of iterations and returning it. Read more
1.0.0 · source§

fn last(self) -> Option<Self::Item>
where Self: Sized,

Consumes the iterator, returning the last element. Read more
source§

fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>>

🔬This is a nightly-only experimental API. (iter_advance_by)
Advances the iterator by n elements. Read more
1.0.0 · source§

fn nth(&mut self, n: usize) -> Option<Self::Item>

Returns the nth element of the iterator. Read more
1.28.0 · source§

fn step_by(self, step: usize) -> StepBy<Self>
where Self: Sized,

Creates an iterator starting at the same point, but stepping by the given amount at each iteration. Read more
1.0.0 · source§

fn chain<U>(self, other: U) -> Chain<Self, <U as IntoIterator>::IntoIter>
where Self: Sized, U: IntoIterator<Item = Self::Item>,

Takes two iterators and creates a new iterator over both in sequence. Read more
1.0.0 · source§

fn zip<U>(self, other: U) -> Zip<Self, <U as IntoIterator>::IntoIter>
where Self: Sized, U: IntoIterator,

‘Zips up’ two iterators into a single iterator of pairs. Read more
source§

fn intersperse_with<G>(self, separator: G) -> IntersperseWith<Self, G>
where Self: Sized, G: FnMut() -> Self::Item,

🔬This is a nightly-only experimental API. (iter_intersperse)
Creates a new iterator which places an item generated by separator between adjacent items of the original iterator. Read more
1.0.0 · source§

fn map<B, F>(self, f: F) -> Map<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> B,

Takes a closure and creates an iterator which calls that closure on each element. Read more
1.21.0 · source§

fn for_each<F>(self, f: F)
where Self: Sized, F: FnMut(Self::Item),

Calls a closure on each element of an iterator. Read more
1.0.0 · source§

fn filter<P>(self, predicate: P) -> Filter<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Creates an iterator which uses a closure to determine if an element should be yielded. Read more
1.0.0 · source§

fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F>
where Self: Sized, F: FnMut(Self::Item) -> Option<B>,

Creates an iterator that both filters and maps. Read more
1.0.0 · source§

fn enumerate(self) -> Enumerate<Self>
where Self: Sized,

Creates an iterator which gives the current iteration count as well as the next value. Read more
1.0.0 · source§

fn peekable(self) -> Peekable<Self>
where Self: Sized,

Creates an iterator which can use the peek and peek_mut methods to look at the next element of the iterator without consuming it. See their documentation for more information. Read more
1.0.0 · source§

fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Creates an iterator that skips elements based on a predicate. Read more
1.0.0 · source§

fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Creates an iterator that yields elements based on a predicate. Read more
1.57.0 · source§

fn map_while<B, P>(self, predicate: P) -> MapWhile<Self, P>
where Self: Sized, P: FnMut(Self::Item) -> Option<B>,

Creates an iterator that both yields elements based on a predicate and maps. Read more
1.0.0 · source§

fn skip(self, n: usize) -> Skip<Self>
where Self: Sized,

Creates an iterator that skips the first n elements. Read more
1.0.0 · source§

fn take(self, n: usize) -> Take<Self>
where Self: Sized,

Creates an iterator that yields the first n elements, or fewer if the underlying iterator ends sooner. Read more
1.0.0 · source§

fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F>
where Self: Sized, F: FnMut(&mut St, Self::Item) -> Option<B>,

An iterator adapter which, like fold, holds internal state, but unlike fold, produces a new iterator. Read more
1.0.0 · source§

fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F>
where Self: Sized, U: IntoIterator, F: FnMut(Self::Item) -> U,

Creates an iterator that works like map, but flattens nested structure. Read more
source§

fn map_windows<F, R, const N: usize>(self, f: F) -> MapWindows<Self, F, N>
where Self: Sized, F: FnMut(&[Self::Item; N]) -> R,

🔬This is a nightly-only experimental API. (iter_map_windows)
Calls the given function f for each contiguous window of size N over self and returns an iterator over the outputs of f. Like slice::windows(), the windows during mapping overlap as well. Read more
1.0.0 · source§

fn fuse(self) -> Fuse<Self>
where Self: Sized,

Creates an iterator which ends after the first None. Read more
1.0.0 · source§

fn inspect<F>(self, f: F) -> Inspect<Self, F>
where Self: Sized, F: FnMut(&Self::Item),

Does something with each element of an iterator, passing the value on. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Borrows an iterator, rather than consuming it. Read more
1.0.0 · source§

fn collect<B>(self) -> B
where B: FromIterator<Self::Item>, Self: Sized,

Transforms an iterator into a collection. Read more
source§

fn collect_into<E>(self, collection: &mut E) -> &mut E
where E: Extend<Self::Item>, Self: Sized,

🔬This is a nightly-only experimental API. (iter_collect_into)
Collects all the items from an iterator into a collection. Read more
1.0.0 · source§

fn partition<B, F>(self, f: F) -> (B, B)
where Self: Sized, B: Default + Extend<Self::Item>, F: FnMut(&Self::Item) -> bool,

Consumes an iterator, creating two collections from it. Read more
source§

fn is_partitioned<P>(self, predicate: P) -> bool
where Self: Sized, P: FnMut(Self::Item) -> bool,

🔬This is a nightly-only experimental API. (iter_is_partitioned)
Checks if the elements of this iterator are partitioned according to the given predicate, such that all those that return true precede all those that return false. Read more
1.27.0 · source§

fn try_fold<B, F, R>(&mut self, init: B, f: F) -> R
where Self: Sized, F: FnMut(B, Self::Item) -> R, R: Try<Output = B>,

An iterator method that applies a function as long as it returns successfully, producing a single, final value. Read more
1.27.0 · source§

fn try_for_each<F, R>(&mut self, f: F) -> R
where Self: Sized, F: FnMut(Self::Item) -> R, R: Try<Output = ()>,

An iterator method that applies a fallible function to each item in the iterator, stopping at the first error and returning that error. Read more
1.0.0 · source§

fn fold<B, F>(self, init: B, f: F) -> B
where Self: Sized, F: FnMut(B, Self::Item) -> B,

Folds every element into an accumulator by applying an operation, returning the final result. Read more
1.51.0 · source§

fn reduce<F>(self, f: F) -> Option<Self::Item>
where Self: Sized, F: FnMut(Self::Item, Self::Item) -> Self::Item,

Reduces the elements to a single one, by repeatedly applying a reducing operation. Read more
source§

fn try_reduce<F, R>( &mut self, f: F ) -> <<R as Try>::Residual as Residual<Option<<R as Try>::Output>>>::TryType
where Self: Sized, F: FnMut(Self::Item, Self::Item) -> R, R: Try<Output = Self::Item>, <R as Try>::Residual: Residual<Option<Self::Item>>,

🔬This is a nightly-only experimental API. (iterator_try_reduce)
Reduces the elements to a single one by repeatedly applying a reducing operation. If the closure returns a failure, the failure is propagated back to the caller immediately. Read more
1.0.0 · source§

fn all<F>(&mut self, f: F) -> bool
where Self: Sized, F: FnMut(Self::Item) -> bool,

Tests if every element of the iterator matches a predicate. Read more
1.0.0 · source§

fn any<F>(&mut self, f: F) -> bool
where Self: Sized, F: FnMut(Self::Item) -> bool,

Tests if any element of the iterator matches a predicate. Read more
1.0.0 · source§

fn find<P>(&mut self, predicate: P) -> Option<Self::Item>
where Self: Sized, P: FnMut(&Self::Item) -> bool,

Searches for an element of an iterator that satisfies a predicate. Read more
1.30.0 · source§

fn find_map<B, F>(&mut self, f: F) -> Option<B>
where Self: Sized, F: FnMut(Self::Item) -> Option<B>,

Applies function to the elements of iterator and returns the first non-none result. Read more
source§

fn try_find<F, R>( &mut self, f: F ) -> <<R as Try>::Residual as Residual<Option<Self::Item>>>::TryType
where Self: Sized, F: FnMut(&Self::Item) -> R, R: Try<Output = bool>, <R as Try>::Residual: Residual<Option<Self::Item>>,

🔬This is a nightly-only experimental API. (try_find)
Applies function to the elements of iterator and returns the first true result or the first error. Read more
1.0.0 · source§

fn position<P>(&mut self, predicate: P) -> Option<usize>
where Self: Sized, P: FnMut(Self::Item) -> bool,

Searches for an element in an iterator, returning its index. Read more
1.6.0 · source§

fn max_by_key<B, F>(self, f: F) -> Option<Self::Item>
where B: Ord, Self: Sized, F: FnMut(&Self::Item) -> B,

Returns the element that gives the maximum value from the specified function. Read more
1.15.0 · source§

fn max_by<F>(self, compare: F) -> Option<Self::Item>
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,

Returns the element that gives the maximum value with respect to the specified comparison function. Read more
1.6.0 · source§

fn min_by_key<B, F>(self, f: F) -> Option<Self::Item>
where B: Ord, Self: Sized, F: FnMut(&Self::Item) -> B,

Returns the element that gives the minimum value from the specified function. Read more
1.15.0 · source§

fn min_by<F>(self, compare: F) -> Option<Self::Item>
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> Ordering,

Returns the element that gives the minimum value with respect to the specified comparison function. Read more
1.0.0 · source§

fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)
where FromA: Default + Extend<A>, FromB: Default + Extend<B>, Self: Sized + Iterator<Item = (A, B)>,

Converts an iterator of pairs into a pair of containers. Read more
1.36.0 · source§

fn copied<'a, T>(self) -> Copied<Self>
where T: 'a + Copy, Self: Sized + Iterator<Item = &'a T>,

Creates an iterator which copies all of its elements. Read more
1.0.0 · source§

fn cloned<'a, T>(self) -> Cloned<Self>
where T: 'a + Clone, Self: Sized + Iterator<Item = &'a T>,

Creates an iterator which clones all of its elements. Read more
1.0.0 · source§

fn cycle(self) -> Cycle<Self>
where Self: Sized + Clone,

Repeats an iterator endlessly. Read more
source§

fn array_chunks<const N: usize>(self) -> ArrayChunks<Self, N>
where Self: Sized,

🔬This is a nightly-only experimental API. (iter_array_chunks)
Returns an iterator over N elements of the iterator at a time. Read more
1.11.0 · source§

fn sum<S>(self) -> S
where Self: Sized, S: Sum<Self::Item>,

Sums the elements of an iterator. Read more
1.11.0 · source§

fn product<P>(self) -> P
where Self: Sized, P: Product<Self::Item>,

Iterates over the entire iterator, multiplying all the elements Read more
source§

fn cmp_by<I, F>(self, other: I, cmp: F) -> Ordering
where Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Ordering,

🔬This is a nightly-only experimental API. (iter_order_by)
Lexicographically compares the elements of this Iterator with those of another with respect to the specified comparison function. Read more
1.5.0 · source§

fn partial_cmp<I>(self, other: I) -> Option<Ordering>
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Lexicographically compares the PartialOrd elements of this Iterator with those of another. The comparison works like short-circuit evaluation, returning a result without comparing the remaining elements. As soon as an order can be determined, the evaluation stops and a result is returned. Read more
source§

fn partial_cmp_by<I, F>(self, other: I, partial_cmp: F) -> Option<Ordering>
where Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> Option<Ordering>,

🔬This is a nightly-only experimental API. (iter_order_by)
Lexicographically compares the elements of this Iterator with those of another with respect to the specified comparison function. Read more
1.5.0 · source§

fn eq<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialEq<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are equal to those of another. Read more
source§

fn eq_by<I, F>(self, other: I, eq: F) -> bool
where Self: Sized, I: IntoIterator, F: FnMut(Self::Item, <I as IntoIterator>::Item) -> bool,

🔬This is a nightly-only experimental API. (iter_order_by)
Determines if the elements of this Iterator are equal to those of another with respect to the specified equality function. Read more
1.5.0 · source§

fn ne<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialEq<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are not equal to those of another. Read more
1.5.0 · source§

fn lt<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically less than those of another. Read more
1.5.0 · source§

fn le<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically less or equal to those of another. Read more
1.5.0 · source§

fn gt<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically greater than those of another. Read more
1.5.0 · source§

fn ge<I>(self, other: I) -> bool
where I: IntoIterator, Self::Item: PartialOrd<<I as IntoIterator>::Item>, Self: Sized,

Determines if the elements of this Iterator are lexicographically greater than or equal to those of another. Read more
source§

fn is_sorted_by<F>(self, compare: F) -> bool
where Self: Sized, F: FnMut(&Self::Item, &Self::Item) -> bool,

🔬This is a nightly-only experimental API. (is_sorted)
Checks if the elements of this iterator are sorted using the given comparator function. Read more
source§

fn is_sorted_by_key<F, K>(self, f: F) -> bool
where Self: Sized, F: FnMut(Self::Item) -> K, K: PartialOrd,

🔬This is a nightly-only experimental API. (is_sorted)
Checks if the elements of this iterator are sorted using the given key extraction function. Read more
source§

impl<'py> Mul<&Bound<'py, PyComplex>> for Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the * operator.
source§

fn mul(self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the * operation. Read more
source§

impl<'py> Mul<Bound<'py, PyComplex>> for &Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the * operator.
source§

fn mul(self, other: Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the * operation. Read more
source§

impl<'py> Mul for &Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the * operator.
source§

fn mul(self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the * operation. Read more
source§

impl<'py> Mul for Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the * operator.
source§

fn mul(self, other: Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the * operation. Read more
source§

impl<'py> Neg for &Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the - operator.
source§

fn neg(self) -> Bound<'py, PyComplex>

Performs the unary - operation. Read more
source§

impl<'py> Neg for Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the - operator.
source§

fn neg(self) -> Bound<'py, PyComplex>

Performs the unary - operation. Read more
source§

impl<'py> PyAnyMethods<'py> for Bound<'py, PyAny>

source§

fn add<O>(&self, other: O) -> PyResult<Bound<'py, PyAny>>
where O: ToPyObject,

Computes self + other.

source§

fn sub<O>(&self, other: O) -> PyResult<Bound<'py, PyAny>>
where O: ToPyObject,

Computes self - other.

source§

fn mul<O>(&self, other: O) -> PyResult<Bound<'py, PyAny>>
where O: ToPyObject,

Computes self * other.

source§

fn div<O>(&self, other: O) -> PyResult<Bound<'py, PyAny>>
where O: ToPyObject,

Computes self / other.

source§

fn lshift<O>(&self, other: O) -> PyResult<Bound<'py, PyAny>>
where O: ToPyObject,

Computes self << other.

source§

fn rshift<O>(&self, other: O) -> PyResult<Bound<'py, PyAny>>
where O: ToPyObject,

Computes self >> other.

source§

fn bitand<O>(&self, other: O) -> PyResult<Bound<'py, PyAny>>
where O: ToPyObject,

Computes self & other.

source§

fn bitor<O>(&self, other: O) -> PyResult<Bound<'py, PyAny>>
where O: ToPyObject,

Computes self | other.

source§

fn bitxor<O>(&self, other: O) -> PyResult<Bound<'py, PyAny>>
where O: ToPyObject,

Computes self ^ other.

source§

fn pow<O1, O2>(&self, other: O1, modulus: O2) -> PyResult<Bound<'py, PyAny>>
where O1: ToPyObject, O2: ToPyObject,

Computes self ** other % modulus (pow(self, other, modulus)). py.None() may be passed for the modulus.

source§

fn is<T: AsPyPointer>(&self, other: &T) -> bool

Returns whether self and other point to the same object. To compare the equality of two objects (the == operator), use eq. Read more
source§

fn hasattr<N>(&self, attr_name: N) -> PyResult<bool>
where N: IntoPy<Py<PyString>>,

Determines whether this object has the given attribute. Read more
source§

fn getattr<N>(&self, attr_name: N) -> PyResult<Bound<'py, PyAny>>
where N: IntoPy<Py<PyString>>,

Retrieves an attribute value. Read more
source§

fn setattr<N, V>(&self, attr_name: N, value: V) -> PyResult<()>
where N: IntoPy<Py<PyString>>, V: ToPyObject,

Sets an attribute value. Read more
source§

fn delattr<N>(&self, attr_name: N) -> PyResult<()>
where N: IntoPy<Py<PyString>>,

Deletes an attribute. Read more
source§

fn compare<O>(&self, other: O) -> PyResult<Ordering>
where O: ToPyObject,

Returns an Ordering between self and other. Read more
source§

fn rich_compare<O>( &self, other: O, compare_op: CompareOp ) -> PyResult<Bound<'py, PyAny>>
where O: ToPyObject,

Tests whether two Python objects obey a given CompareOp. Read more
source§

fn lt<O>(&self, other: O) -> PyResult<bool>
where O: ToPyObject,

Tests whether this object is less than another. Read more
source§

fn le<O>(&self, other: O) -> PyResult<bool>
where O: ToPyObject,

Tests whether this object is less than or equal to another. Read more
source§

fn eq<O>(&self, other: O) -> PyResult<bool>
where O: ToPyObject,

Tests whether this object is equal to another. Read more
source§

fn ne<O>(&self, other: O) -> PyResult<bool>
where O: ToPyObject,

Tests whether this object is not equal to another. Read more
source§

fn gt<O>(&self, other: O) -> PyResult<bool>
where O: ToPyObject,

Tests whether this object is greater than another. Read more
source§

fn ge<O>(&self, other: O) -> PyResult<bool>
where O: ToPyObject,

Tests whether this object is greater than or equal to another. Read more
source§

fn is_callable(&self) -> bool

Determines whether this object appears callable. Read more
source§

fn call( &self, args: impl IntoPy<Py<PyTuple>>, kwargs: Option<&Bound<'_, PyDict>> ) -> PyResult<Bound<'py, PyAny>>

Calls the object. Read more
source§

fn call0(&self) -> PyResult<Bound<'py, PyAny>>

Calls the object without arguments. Read more
source§

fn call1(&self, args: impl IntoPy<Py<PyTuple>>) -> PyResult<Bound<'py, PyAny>>

Calls the object with only positional arguments. Read more
source§

fn call_method<N, A>( &self, name: N, args: A, kwargs: Option<&Bound<'_, PyDict>> ) -> PyResult<Bound<'py, PyAny>>
where N: IntoPy<Py<PyString>>, A: IntoPy<Py<PyTuple>>,

Calls a method on the object. Read more
source§

fn call_method0<N>(&self, name: N) -> PyResult<Bound<'py, PyAny>>
where N: IntoPy<Py<PyString>>,

Calls a method on the object without arguments. Read more
source§

fn call_method1<N, A>(&self, name: N, args: A) -> PyResult<Bound<'py, PyAny>>
where N: IntoPy<Py<PyString>>, A: IntoPy<Py<PyTuple>>,

Calls a method on the object with only positional arguments. Read more
source§

fn is_truthy(&self) -> PyResult<bool>

Returns whether the object is considered to be true. Read more
source§

fn is_none(&self) -> bool

Returns whether the object is considered to be None. Read more
source§

fn is_ellipsis(&self) -> bool

Returns whether the object is Ellipsis, e.g. .... Read more
source§

fn is_empty(&self) -> PyResult<bool>

Returns true if the sequence or mapping has a length of 0. Read more
source§

fn get_item<K>(&self, key: K) -> PyResult<Bound<'py, PyAny>>
where K: ToPyObject,

Gets an item from the collection. Read more
source§

fn set_item<K, V>(&self, key: K, value: V) -> PyResult<()>
where K: ToPyObject, V: ToPyObject,

Sets a collection item value. Read more
source§

fn del_item<K>(&self, key: K) -> PyResult<()>
where K: ToPyObject,

Deletes an item from the collection. Read more
source§

fn iter(&self) -> PyResult<Bound<'py, PyIterator>>

Takes an object and returns an iterator for it. Read more
source§

fn get_type(&self) -> Bound<'py, PyType>

Returns the Python type object for this object’s type.
source§

fn get_type_ptr(&self) -> *mut PyTypeObject

Returns the Python type pointer for this object.
source§

fn downcast<T>(&self) -> Result<&Bound<'py, T>, DowncastError<'_, 'py>>
where T: PyTypeCheck,

Downcast this PyAny to a concrete Python type or pyclass. Read more
source§

fn downcast_into<T>(self) -> Result<Bound<'py, T>, DowncastIntoError<'py>>
where T: PyTypeCheck,

Like downcast but takes ownership of self. Read more
source§

fn downcast_exact<T>(&self) -> Result<&Bound<'py, T>, DowncastError<'_, 'py>>
where T: PyTypeInfo,

Downcast this PyAny to a concrete Python type or pyclass (but not a subclass of it). Read more
source§

fn downcast_into_exact<T>(self) -> Result<Bound<'py, T>, DowncastIntoError<'py>>
where T: PyTypeInfo,

Like downcast_exact but takes ownership of self.
source§

unsafe fn downcast_unchecked<T>(&self) -> &Bound<'py, T>

Converts this PyAny to a concrete Python type without checking validity. Read more
source§

unsafe fn downcast_into_unchecked<T>(self) -> Bound<'py, T>

Like downcast_unchecked but takes ownership of self. Read more
source§

fn extract<'a, T>(&'a self) -> PyResult<T>
where T: FromPyObjectBound<'a, 'py>,

Extracts some type from the Python object. Read more
source§

fn get_refcnt(&self) -> isize

Returns the reference count for the Python object.
source§

fn repr(&self) -> PyResult<Bound<'py, PyString>>

Computes the “repr” representation of self. Read more
source§

fn str(&self) -> PyResult<Bound<'py, PyString>>

Computes the “str” representation of self. Read more
source§

fn hash(&self) -> PyResult<isize>

Retrieves the hash code of self. Read more
source§

fn len(&self) -> PyResult<usize>

Returns the length of the sequence or mapping. Read more
source§

fn dir(&self) -> PyResult<Bound<'py, PyList>>

Returns the list of attributes of this object. Read more
source§

fn is_instance(&self, ty: &Bound<'py, PyAny>) -> PyResult<bool>

Checks whether this object is an instance of type ty. Read more
source§

fn is_exact_instance(&self, ty: &Bound<'py, PyAny>) -> bool

Checks whether this object is an instance of exactly type ty (not a subclass). Read more
source§

fn is_instance_of<T: PyTypeInfo>(&self) -> bool

Checks whether this object is an instance of type T. Read more
source§

fn is_exact_instance_of<T: PyTypeInfo>(&self) -> bool

Checks whether this object is an instance of exactly type T. Read more
source§

fn contains<V>(&self, value: V) -> PyResult<bool>
where V: ToPyObject,

Determines if self contains value. Read more
source§

fn py_super(&self) -> PyResult<Bound<'py, PySuper>>

Return a proxy object that delegates method calls to a parent or sibling class of type. Read more
source§

impl<'py> PyBoolMethods<'py> for Bound<'py, PyBool>

source§

fn is_true(&self) -> bool

Gets whether this boolean is true.
source§

impl<'py> PyByteArrayMethods<'py> for Bound<'py, PyByteArray>

source§

fn len(&self) -> usize

Gets the length of the bytearray.
source§

fn is_empty(&self) -> bool

Checks if the bytearray is empty.
source§

fn data(&self) -> *mut u8

Gets the start of the buffer containing the contents of the bytearray. Read more
source§

unsafe fn as_bytes(&self) -> &[u8]

Extracts a slice of the ByteArray’s entire buffer. Read more
source§

unsafe fn as_bytes_mut(&self) -> &mut [u8]

Extracts a mutable slice of the ByteArray’s entire buffer. Read more
source§

fn to_vec(&self) -> Vec<u8>

Copies the contents of the bytearray to a Rust vector. Read more
source§

fn resize(&self, len: usize) -> PyResult<()>

Resizes the bytearray object to the new length len. Read more
source§

impl<'py> PyBytesMethods<'py> for Bound<'py, PyBytes>

source§

fn as_bytes(&self) -> &[u8]

Gets the Python string as a byte slice.
source§

impl<'py> PyCapsuleMethods<'py> for Bound<'py, PyCapsule>

source§

fn set_context(&self, context: *mut c_void) -> PyResult<()>

Sets the context pointer in the capsule. Read more
source§

fn context(&self) -> PyResult<*mut c_void>

Gets the current context stored in the capsule. If there is no context, the pointer will be null. Read more
source§

unsafe fn reference<T>(&self) -> &'py T

Obtains a reference to the value of this capsule. Read more
source§

fn pointer(&self) -> *mut c_void

Gets the raw c_void pointer to the value in this capsule. Read more
source§

fn is_valid(&self) -> bool

Checks if this is a valid capsule. Read more
source§

fn name(&self) -> PyResult<Option<&'py CStr>>

Retrieves the name of this capsule, if set. Read more
source§

impl<'py> PyComplexMethods<'py> for Bound<'py, PyComplex>

source§

fn real(&self) -> c_double

Returns the real part of the complex number.
source§

fn imag(&self) -> c_double

Returns the imaginary part of the complex number.
source§

fn abs(&self) -> c_double

Returns |self|.
source§

fn pow(&self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Returns self raised to the power of other.
source§

impl PyDateAccess for Bound<'_, PyDate>

source§

fn get_year(&self) -> i32

Returns the year, as a positive int. Read more
source§

fn get_month(&self) -> u8

Returns the month, as an int from 1 through 12. Read more
source§

fn get_day(&self) -> u8

Returns the day, as an int from 1 through 31. Read more
source§

impl PyDateAccess for Bound<'_, PyDateTime>

source§

fn get_year(&self) -> i32

Returns the year, as a positive int. Read more
source§

fn get_month(&self) -> u8

Returns the month, as an int from 1 through 12. Read more
source§

fn get_day(&self) -> u8

Returns the day, as an int from 1 through 31. Read more
source§

impl PyDeltaAccess for Bound<'_, PyDelta>

source§

fn get_days(&self) -> i32

Returns the number of days, as an int from -999999999 to 999999999. Read more
source§

fn get_seconds(&self) -> i32

Returns the number of seconds, as an int from 0 through 86399. Read more
source§

fn get_microseconds(&self) -> i32

Returns the number of microseconds, as an int from 0 through 999999. Read more
source§

impl<'py> PyDictMethods<'py> for Bound<'py, PyDict>

source§

fn copy(&self) -> PyResult<Bound<'py, PyDict>>

Returns a new dictionary that contains the same key-value pairs as self. Read more
source§

fn clear(&self)

Empties an existing dictionary of all key-value pairs.
source§

fn len(&self) -> usize

Return the number of items in the dictionary. Read more
source§

fn is_empty(&self) -> bool

Checks if the dict is empty, i.e. len(self) == 0.
source§

fn contains<K>(&self, key: K) -> PyResult<bool>
where K: ToPyObject,

Determines if the dictionary contains the specified key. Read more
source§

fn get_item<K>(&self, key: K) -> PyResult<Option<Bound<'py, PyAny>>>
where K: ToPyObject,

Gets an item from the dictionary. Read more
source§

fn set_item<K, V>(&self, key: K, value: V) -> PyResult<()>
where K: ToPyObject, V: ToPyObject,

Sets an item value. Read more
source§

fn del_item<K>(&self, key: K) -> PyResult<()>
where K: ToPyObject,

Deletes an item. Read more
source§

fn keys(&self) -> Bound<'py, PyList>

Returns a list of dict keys. Read more
source§

fn values(&self) -> Bound<'py, PyList>

Returns a list of dict values. Read more
source§

fn items(&self) -> Bound<'py, PyList>

Returns a list of dict items. Read more
source§

fn iter(&self) -> BoundDictIterator<'py>

Returns an iterator of (key, value) pairs in this dictionary. Read more
source§

fn as_mapping(&self) -> &Bound<'py, PyMapping>

Returns self cast as a PyMapping.
source§

fn into_mapping(self) -> Bound<'py, PyMapping>

Returns self cast as a PyMapping.
source§

fn update(&self, other: &Bound<'_, PyMapping>) -> PyResult<()>

Update this dictionary with the key/value pairs from another. Read more
source§

fn update_if_missing(&self, other: &Bound<'_, PyMapping>) -> PyResult<()>

Add key/value pairs from another dictionary to this one only when they do not exist in this. Read more
source§

impl<'py> PyFloatMethods<'py> for Bound<'py, PyFloat>

source§

fn value(&self) -> c_double

Gets the value of this float.
source§

impl<'py> PyFrozenSetMethods<'py> for Bound<'py, PyFrozenSet>

source§

fn len(&self) -> usize

Returns the number of items in the set. Read more
source§

fn contains<K>(&self, key: K) -> PyResult<bool>
where K: ToPyObject,

Determines if the set contains the specified key. Read more
source§

fn iter(&self) -> BoundFrozenSetIterator<'py>

Returns an iterator of values in this set.
source§

fn is_empty(&self) -> bool

Checks if set is empty.
source§

impl<'py> PyListMethods<'py> for Bound<'py, PyList>

source§

fn len(&self) -> usize

Returns the length of the list.

source§

fn is_empty(&self) -> bool

Checks if the list is empty.

source§

fn as_sequence(&self) -> &Bound<'py, PySequence>

Returns self cast as a PySequence.

source§

fn into_sequence(self) -> Bound<'py, PySequence>

Returns self cast as a PySequence.

source§

fn get_item(&self, index: usize) -> PyResult<Bound<'py, PyAny>>

Gets the list item at the specified index.

§Example
use pyo3::{prelude::*, types::PyList};
Python::with_gil(|py| {
    let list = PyList::new_bound(py, [2, 3, 5, 7]);
    let obj = list.get_item(0);
    assert_eq!(obj.unwrap().extract::<i32>().unwrap(), 2);
});
source§

unsafe fn get_item_unchecked(&self, index: usize) -> Bound<'py, PyAny>

Gets the list item at the specified index. Undefined behavior on bad index. Use with caution.

§Safety

Caller must verify that the index is within the bounds of the list.

source§

fn get_slice(&self, low: usize, high: usize) -> Bound<'py, PyList>

Takes the slice self[low:high] and returns it as a new list.

Indices must be nonnegative, and out-of-range indices are clipped to self.len().

source§

fn set_item<I>(&self, index: usize, item: I) -> PyResult<()>
where I: ToPyObject,

Sets the item at the specified index.

Raises IndexError if the index is out of range.

source§

fn del_item(&self, index: usize) -> PyResult<()>

Deletes the indexth element of self.

This is equivalent to the Python statement del self[i].

source§

fn set_slice( &self, low: usize, high: usize, seq: &Bound<'_, PyAny> ) -> PyResult<()>

Assigns the sequence seq to the slice of self from low to high.

This is equivalent to the Python statement self[low:high] = v.

source§

fn del_slice(&self, low: usize, high: usize) -> PyResult<()>

Deletes the slice from low to high from self.

This is equivalent to the Python statement del self[low:high].

source§

fn append<I>(&self, item: I) -> PyResult<()>
where I: ToPyObject,

Appends an item to the list.

source§

fn insert<I>(&self, index: usize, item: I) -> PyResult<()>
where I: ToPyObject,

Inserts an item at the specified index.

If index >= self.len(), inserts at the end.

source§

fn contains<V>(&self, value: V) -> PyResult<bool>
where V: ToPyObject,

Determines if self contains value.

This is equivalent to the Python expression value in self.

source§

fn index<V>(&self, value: V) -> PyResult<usize>
where V: ToPyObject,

Returns the first index i for which self[i] == value.

This is equivalent to the Python expression self.index(value).

source§

fn iter(&self) -> BoundListIterator<'py>

Returns an iterator over this list’s items.

source§

fn sort(&self) -> PyResult<()>

Sorts the list in-place. Equivalent to the Python expression l.sort().

source§

fn reverse(&self) -> PyResult<()>

Reverses the list in-place. Equivalent to the Python expression l.reverse().

source§

fn to_tuple(&self) -> Bound<'py, PyTuple>

Return a new tuple containing the contents of the list; equivalent to the Python expression tuple(list).

This method is equivalent to self.as_sequence().to_tuple() and faster than PyTuple::new(py, this_list).

source§

impl<'py> PyMappingMethods<'py> for Bound<'py, PyMapping>

source§

fn len(&self) -> PyResult<usize>

Returns the number of objects in the mapping. Read more
source§

fn is_empty(&self) -> PyResult<bool>

Returns whether the mapping is empty.
source§

fn contains<K>(&self, key: K) -> PyResult<bool>
where K: ToPyObject,

Determines if the mapping contains the specified key. Read more
source§

fn get_item<K>(&self, key: K) -> PyResult<Bound<'py, PyAny>>
where K: ToPyObject,

Gets the item in self with key key. Read more
source§

fn set_item<K, V>(&self, key: K, value: V) -> PyResult<()>
where K: ToPyObject, V: ToPyObject,

Sets the item in self with key key. Read more
source§

fn del_item<K>(&self, key: K) -> PyResult<()>
where K: ToPyObject,

Deletes the item with key key. Read more
source§

fn keys(&self) -> PyResult<Bound<'py, PySequence>>

Returns a sequence containing all keys in the mapping.
source§

fn values(&self) -> PyResult<Bound<'py, PySequence>>

Returns a sequence containing all values in the mapping.
source§

fn items(&self) -> PyResult<Bound<'py, PySequence>>

Returns a sequence of tuples of all (key, value) pairs in the mapping.
source§

impl<'py> PyModuleMethods<'py> for Bound<'py, PyModule>

source§

fn dict(&self) -> Bound<'py, PyDict>

Returns the module’s __dict__ attribute, which contains the module’s symbol table.
source§

fn index(&self) -> PyResult<Bound<'py, PyList>>

Returns the index (the __all__ attribute) of the module, creating one if needed. Read more
source§

fn name(&self) -> PyResult<Bound<'py, PyString>>

Returns the name (the __name__ attribute) of the module. Read more
source§

fn filename(&self) -> PyResult<Bound<'py, PyString>>

Returns the filename (the __file__ attribute) of the module. Read more
source§

fn add<N, V>(&self, name: N, value: V) -> PyResult<()>
where N: IntoPy<Py<PyString>>, V: IntoPy<PyObject>,

Adds an attribute to the module. Read more
source§

fn add_class<T>(&self) -> PyResult<()>
where T: PyClass,

Adds a new class to the module. Read more
source§

fn add_wrapped<T>(&self, wrapper: &impl Fn(Python<'py>) -> T) -> PyResult<()>
where T: IntoPyCallbackOutput<PyObject>,

Adds a function or a (sub)module to a module, using the functions name as name. Read more
source§

fn add_submodule(&self, module: &Bound<'_, PyModule>) -> PyResult<()>

Adds a submodule to a module. Read more
source§

fn add_function(&self, fun: Bound<'_, PyCFunction>) -> PyResult<()>

Add a function to a module. Read more
source§

impl<'py> PySequenceMethods<'py> for Bound<'py, PySequence>

source§

fn len(&self) -> PyResult<usize>

Returns the number of objects in sequence. Read more
source§

fn is_empty(&self) -> PyResult<bool>

Returns whether the sequence is empty.
source§

fn concat( &self, other: &Bound<'_, PySequence> ) -> PyResult<Bound<'py, PySequence>>

Returns the concatenation of self and other. Read more
source§

fn repeat(&self, count: usize) -> PyResult<Bound<'py, PySequence>>

Returns the result of repeating a sequence object count times. Read more
source§

fn in_place_concat( &self, other: &Bound<'_, PySequence> ) -> PyResult<Bound<'py, PySequence>>

Concatenates self and other, in place if possible. Read more
source§

fn in_place_repeat(&self, count: usize) -> PyResult<Bound<'py, PySequence>>

Repeats the sequence object count times and updates self, if possible. Read more
source§

fn get_item(&self, index: usize) -> PyResult<Bound<'py, PyAny>>

Returns the indexth element of the Sequence. Read more
source§

fn get_slice( &self, begin: usize, end: usize ) -> PyResult<Bound<'py, PySequence>>

Returns the slice of sequence object between begin and end. Read more
source§

fn set_item<I>(&self, i: usize, item: I) -> PyResult<()>
where I: ToPyObject,

Assigns object item to the ith element of self. Read more
source§

fn del_item(&self, i: usize) -> PyResult<()>

Deletes the ith element of self. Read more
source§

fn set_slice(&self, i1: usize, i2: usize, v: &Bound<'_, PyAny>) -> PyResult<()>

Assigns the sequence v to the slice of self from i1 to i2. Read more
source§

fn del_slice(&self, i1: usize, i2: usize) -> PyResult<()>

Deletes the slice from i1 to i2 from self. Read more
source§

fn count<V>(&self, value: V) -> PyResult<usize>
where V: ToPyObject,

Returns the number of occurrences of value in self, that is, return the number of keys for which self[key] == value.
source§

fn contains<V>(&self, value: V) -> PyResult<bool>
where V: ToPyObject,

Determines if self contains value. Read more
source§

fn index<V>(&self, value: V) -> PyResult<usize>
where V: ToPyObject,

Returns the first index i for which self[i] == value. Read more
source§

fn to_list(&self) -> PyResult<Bound<'py, PyList>>

Returns a fresh list based on the Sequence.
source§

fn to_tuple(&self) -> PyResult<Bound<'py, PyTuple>>

Returns a fresh tuple based on the Sequence.
source§

impl<'py> PySetMethods<'py> for Bound<'py, PySet>

source§

fn clear(&self)

Removes all elements from the set.
source§

fn len(&self) -> usize

Returns the number of items in the set. Read more
source§

fn contains<K>(&self, key: K) -> PyResult<bool>
where K: ToPyObject,

Determines if the set contains the specified key. Read more
source§

fn discard<K>(&self, key: K) -> PyResult<bool>
where K: ToPyObject,

Removes the element from the set if it is present. Read more
source§

fn add<K>(&self, key: K) -> PyResult<()>
where K: ToPyObject,

Adds an element to the set.
source§

fn pop(&self) -> Option<Bound<'py, PyAny>>

Removes and returns an arbitrary element from the set.
source§

fn iter(&self) -> BoundSetIterator<'py>

Returns an iterator of values in this set. Read more
source§

fn is_empty(&self) -> bool

Checks if set is empty.
source§

impl<'py> PySliceMethods<'py> for Bound<'py, PySlice>

source§

fn indices(&self, length: isize) -> PyResult<PySliceIndices>

Retrieves the start, stop, and step indices from the slice object, assuming a sequence of length length, and stores the length of the slice in its slicelength member.
source§

impl<'py> PyStringMethods<'py> for Bound<'py, PyString>

source§

fn to_str(&self) -> PyResult<&str>

Gets the Python string as a Rust UTF-8 string slice. Read more
source§

fn to_cow(&self) -> PyResult<Cow<'_, str>>

Converts the PyString into a Rust string, avoiding copying when possible. Read more
source§

fn to_string_lossy(&self) -> Cow<'_, str>

Converts the PyString into a Rust string. Read more
source§

fn encode_utf8(&self) -> PyResult<Bound<'py, PyBytes>>

Encodes this string as a Python bytes object, using UTF-8 encoding.
source§

unsafe fn data(&self) -> PyResult<PyStringData<'_>>

Obtains the raw data backing the Python string. Read more
source§

impl PyTimeAccess for Bound<'_, PyDateTime>

source§

fn get_hour(&self) -> u8

Returns the hour, as an int from 0 through 23. Read more
source§

fn get_minute(&self) -> u8

Returns the minute, as an int from 0 through 59. Read more
source§

fn get_second(&self) -> u8

Returns the second, as an int from 0 through 59. Read more
source§

fn get_microsecond(&self) -> u32

Returns the microsecond, as an int from 0 through 999999. Read more
source§

fn get_fold(&self) -> bool

Returns whether this date is the later of two moments with the same representation, during a repeated interval. Read more
source§

impl PyTimeAccess for Bound<'_, PyTime>

source§

fn get_hour(&self) -> u8

Returns the hour, as an int from 0 through 23. Read more
source§

fn get_minute(&self) -> u8

Returns the minute, as an int from 0 through 59. Read more
source§

fn get_second(&self) -> u8

Returns the second, as an int from 0 through 59. Read more
source§

fn get_microsecond(&self) -> u32

Returns the microsecond, as an int from 0 through 999999. Read more
source§

fn get_fold(&self) -> bool

Returns whether this date is the later of two moments with the same representation, during a repeated interval. Read more
source§

impl<'py> PyTracebackMethods<'py> for Bound<'py, PyTraceback>

source§

fn format(&self) -> PyResult<String>

Formats the traceback as a string. Read more
source§

impl<'py> PyTupleMethods<'py> for Bound<'py, PyTuple>

source§

fn len(&self) -> usize

Gets the length of the tuple.
source§

fn is_empty(&self) -> bool

Checks if the tuple is empty.
source§

fn as_sequence(&self) -> &Bound<'py, PySequence>

Returns self cast as a PySequence.
source§

fn into_sequence(self) -> Bound<'py, PySequence>

Returns self cast as a PySequence.
source§

fn get_slice(&self, low: usize, high: usize) -> Bound<'py, PyTuple>

Takes the slice self[low:high] and returns it as a new tuple. Read more
source§

fn get_item(&self, index: usize) -> PyResult<Bound<'py, PyAny>>

Gets the tuple item at the specified index. Read more
source§

fn get_borrowed_item<'a>( &'a self, index: usize ) -> PyResult<Borrowed<'a, 'py, PyAny>>

Like get_item, but returns a borrowed object, which is a slight performance optimization by avoiding a reference count change.
source§

unsafe fn get_item_unchecked(&self, index: usize) -> Bound<'py, PyAny>

Gets the tuple item at the specified index. Undefined behavior on bad index. Use with caution. Read more
source§

unsafe fn get_borrowed_item_unchecked<'a>( &'a self, index: usize ) -> Borrowed<'a, 'py, PyAny>

Like get_item_unchecked, but returns a borrowed object, which is a slight performance optimization by avoiding a reference count change. Read more
source§

fn as_slice(&self) -> &[Bound<'py, PyAny>]

Returns self as a slice of objects.
source§

fn contains<V>(&self, value: V) -> PyResult<bool>
where V: ToPyObject,

Determines if self contains value. Read more
source§

fn index<V>(&self, value: V) -> PyResult<usize>
where V: ToPyObject,

Returns the first index i for which self[i] == value. Read more
source§

fn iter(&self) -> BoundTupleIterator<'py>

Returns an iterator over the tuple items.
source§

fn iter_borrowed<'a>(&'a self) -> BorrowedTupleIterator<'a, 'py>

Like iter, but produces an iterator which returns borrowed objects, which is a slight performance optimization by avoiding a reference count change.
source§

fn to_list(&self) -> Bound<'py, PyList>

Return a new list containing the contents of this tuple; equivalent to the Python expression list(tuple). Read more
source§

impl<'py> PyTypeMethods<'py> for Bound<'py, PyType>

source§

fn as_type_ptr(&self) -> *mut PyTypeObject

Retrieves the underlying FFI pointer associated with this Python object.

source§

fn name(&self) -> PyResult<Cow<'_, str>>

Gets the name of the PyType.

source§

fn is_subclass(&self, other: &Bound<'_, PyAny>) -> PyResult<bool>

Checks whether self is a subclass of other.

Equivalent to the Python expression issubclass(self, other).

source§

fn is_subclass_of<T>(&self) -> PyResult<bool>
where T: PyTypeInfo,

Checks whether self is a subclass of type T.

Equivalent to the Python expression issubclass(self, T), if the type T is known at compile time.

source§

fn qualname(&self) -> PyResult<String>

Gets the qualified name of the PyType.
source§

impl<'py> PyTzInfoAccess<'py> for Bound<'py, PyDateTime>

source§

fn get_tzinfo_bound(&self) -> Option<Bound<'py, PyTzInfo>>

Returns the tzinfo (which may be None). Read more
source§

impl<'py> PyTzInfoAccess<'py> for Bound<'py, PyTime>

source§

fn get_tzinfo_bound(&self) -> Option<Bound<'py, PyTzInfo>>

Returns the tzinfo (which may be None). Read more
source§

impl<'py> Sub<&Bound<'py, PyComplex>> for Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the - operator.
source§

fn sub(self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the - operation. Read more
source§

impl<'py> Sub<Bound<'py, PyComplex>> for &Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the - operator.
source§

fn sub(self, other: Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the - operation. Read more
source§

impl<'py> Sub for &Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the - operator.
source§

fn sub(self, other: &Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the - operation. Read more
source§

impl<'py> Sub for Bound<'py, PyComplex>

§

type Output = Bound<'py, PyComplex>

The resulting type after applying the - operator.
source§

fn sub(self, other: Bound<'py, PyComplex>) -> Bound<'py, PyComplex>

Performs the - operation. Read more
source§

impl<T> ToPyObject for Bound<'_, T>

source§

fn to_object(&self, py: Python<'_>) -> PyObject

Converts &Bound instance -> PyObject, increasing the reference count.

source§

impl<'py> TryFrom<&Bound<'py, PyAny>> for Bound<'py, PyByteArray>

source§

fn try_from(value: &Bound<'py, PyAny>) -> Result<Self, Self::Error>

Creates a new Python bytearray object from another Python object that implements the buffer protocol.

§

type Error = PyErr

The type returned in the event of a conversion error.
source§

impl<'py> TryFrom<&Bound<'py, PyAny>> for Bound<'py, PyMemoryView>

source§

fn try_from(value: &Bound<'py, PyAny>) -> Result<Self, Self::Error>

Creates a new Python memoryview object from another Python object that implements the buffer protocol.

§

type Error = PyErr

The type returned in the event of a conversion error.
source§

impl TryFrom<Bound<'_, PyString>> for PyBackedStr

§

type Error = PyErr

The type returned in the event of a conversion error.
source§

fn try_from(py_string: Bound<'_, PyString>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'py, T> RefUnwindSafe for Bound<'py, T>
where T: RefUnwindSafe,

§

impl<'py, T> !Send for Bound<'py, T>

§

impl<'py, T> !Sync for Bound<'py, T>

§

impl<'py, T> Unpin for Bound<'py, T>
where T: Unpin,

§

impl<'py, T> UnwindSafe for Bound<'py, T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<'py, T> FromPyObjectBound<'_, 'py> for T
where T: FromPyObject<'py>,

source§

fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
source§

fn type_input() -> TypeInfo

Extracts the type hint information for this type when it appears as an argument. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<I> IntoIterator for I
where I: Iterator,

§

type Item = <I as Iterator>::Item

The type of the elements being iterated over.
§

type IntoIter = I

Which kind of iterator are we turning this into?
const: unstable · source§

fn into_iter(self) -> I

Creates an iterator from a value. Read more
source§

impl<T, I> IntoPyDict for I
where T: PyDictItem, I: IntoIterator<Item = T>,

source§

fn into_py_dict_bound(self, py: Python<'_>) -> Bound<'_, PyDict>

Converts self into a PyDict object pointer. Whether pointer owned or borrowed depends on implementation.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.