pyo3::instance

Struct Borrowed

Source
#[repr(transparent)]
pub struct Borrowed<'a, 'py, T>(NonNull<PyObject>, PhantomData<&'a Py<T>>, Python<'py>);
Expand description

A borrowed equivalent to Bound.

The advantage of this over &Bound is that it avoids the need to have a pointer-to-pointer, as Bound is already a pointer to an `ffi::PyObject``.

Similarly, this type is Copy and Clone, like a shared reference (&T).

Tuple Fields§

§0: NonNull<PyObject>§1: PhantomData<&'a Py<T>>§2: Python<'py>

Implementations§

Source§

impl Borrowed<'_, '_, PyType>

Source

pub(crate) fn get_slot<const S: c_int>( self, slot: Slot<S>, ) -> <Slot<S> as GetSlotImpl>::Type
where Slot<S>: GetSlotImpl,

Source§

impl<'a, 'py, T> Borrowed<'a, 'py, T>

Source

pub fn to_owned(self) -> Bound<'py, T>

Creates a new owned Bound<T> from this borrowed reference by increasing the reference count.

§Example
use pyo3::{prelude::*, types::PyTuple};

Python::with_gil(|py| -> PyResult<()> {
    let tuple = PyTuple::new(py, [1, 2, 3])?;

    // borrows from `tuple`, so can only be
    // used while `tuple` stays alive
    let borrowed = tuple.get_borrowed_item(0)?;

    // creates a new owned reference, which
    // can be used indendently of `tuple`
    let bound = borrowed.to_owned();
    drop(tuple);

    assert_eq!(bound.extract::<i32>().unwrap(), 1);
    Ok(())
})
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(crate) fn to_any(self) -> Borrowed<'a, 'py, PyAny>

Source§

impl<'a, 'py> Borrowed<'a, 'py, PyAny>

Source

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

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

Prefer to use Bound::from_borrowed_ptr, as that avoids the major safety risk of needing to precisely define the lifetime 'a for which the borrow is valid.

§Safety
  • ptr must be a valid pointer to a Python object
  • similar to std::slice::from_raw_parts, the lifetime 'a is completely defined by the caller and it is the caller’s responsibility to ensure that the reference this is derived from is valid for the lifetime 'a.
Source

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

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

Prefer to use Bound::from_borrowed_ptr_or_opt, as that avoids the major safety risk of needing to precisely define the lifetime 'a for which the borrow is valid.

§Safety
  • ptr must be a valid pointer to a Python object, or null
  • similar to std::slice::from_raw_parts, the lifetime 'a is completely defined by the caller and it is the caller’s responsibility to ensure that the reference this is derived from is valid for the lifetime 'a.
Source

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

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

Prefer to use Bound::from_borrowed_ptr_or_err, as that avoids the major safety risk of needing to precisely define the lifetime 'a for which the borrow is valid.

§Safety
  • ptr must be a valid pointer to a Python object, or null
  • similar to std::slice::from_raw_parts, the lifetime 'a is completely defined by the caller and it is the caller’s responsibility to ensure that the reference this is derived from is valid for the lifetime 'a.
Source

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

§Safety

This is similar to std::slice::from_raw_parts, the lifetime 'a is completely defined by the caller and it’s the caller’s responsibility to ensure that the reference this is derived from is valid for the lifetime 'a.

Source

pub(crate) fn downcast<T>( self, ) -> Result<Borrowed<'a, 'py, T>, DowncastError<'a, 'py>>
where T: PyTypeCheck,

Source

pub(crate) unsafe fn downcast_unchecked<T>(self) -> Borrowed<'a, 'py, T>

Converts this PyAny to a concrete Python type without checking validity.

§Safety

Callers must ensure that the type is valid or risk type confusion.

Source§

impl<'a> Borrowed<'a, '_, PyByteArray>

Source

fn data(&self) -> *mut u8

Source

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

Source

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

Source§

impl<'a> Borrowed<'a, '_, PyBytes>

Source

pub(crate) fn as_bytes(self) -> &'a [u8]

Gets the Python string as a byte slice.

Source§

impl<'a, 'py> Borrowed<'a, 'py, PyDict>

Source

pub(crate) unsafe fn iter_borrowed(self) -> BorrowedDictIter<'a, 'py>

Iterates over the contents of this dictionary without incrementing reference counts.

§Safety

It must be known that this dictionary will not be modified during iteration.

Source§

impl<'py> Borrowed<'_, 'py, PyIterator>

Source

fn next(self) -> Option<PyResult<Bound<'py, PyAny>>>

Source§

impl<'a> Borrowed<'a, '_, PyString>

Source

pub(crate) fn to_str(self) -> PyResult<&'a str>

Available on Py_3_10 or non-Py_LIMITED_API only.
Source

pub(crate) fn to_cow(self) -> PyResult<Cow<'a, str>>

Source

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

Source

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

Available on neither Py_LIMITED_API nor GraalPy nor PyPy.
Source§

impl<'a, 'py> Borrowed<'a, 'py, PyTuple>

Source

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

Source

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

Available on neither Py_LIMITED_API nor PyPy nor GraalPy.
Source

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

Methods from Deref<Target = Bound<'py, T>>§

Source

pub(crate) fn get_slot<const S: c_int>( &self, slot: Slot<S>, ) -> <Slot<S> as GetSlotImpl>::Type
where Slot<S>: GetSlotImpl,

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

pub fn as_super(&self) -> &Bound<'py, T::BaseType>

Upcast this Bound<PyClass> to its base type by reference.

If this type defined an explicit base class in its pyclass declaration (e.g. #[pyclass(extends = BaseType)]), the returned type will be &Bound<BaseType>. If an explicit base class was not declared, the return value will be &Bound<PyAny> (making this method equivalent to as_any).

This method is particularly useful for calling methods defined in an extension trait that has been implemented for Bound<BaseType>.

See also the into_super method to upcast by value, and the PyRef::as_super/PyRefMut::as_super methods for upcasting a pyclass that has already been borrowed.

§Example: Calling a method defined on the Bound base type
use pyo3::prelude::*;

#[pyclass(subclass)]
struct BaseClass;

trait MyClassMethods<'py> {
    fn pyrepr(&self) -> PyResult<String>;
}
impl<'py> MyClassMethods<'py> for Bound<'py, BaseClass> {
    fn pyrepr(&self) -> PyResult<String> {
        self.call_method0("__repr__")?.extract()
    }
}

#[pyclass(extends = BaseClass)]
struct SubClass;

Python::with_gil(|py| {
    let obj = Bound::new(py, (SubClass, BaseClass)).unwrap();
    assert!(obj.as_super().pyrepr().is_ok());
})
Source

pub(crate) fn get_class_object(&self) -> &PyClassObject<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 as_any(&self) -> &Bound<'py, PyAny>

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

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 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(crate) fn lookup_special<N>( &self, attr_name: N, ) -> PyResult<Option<Bound<'py, PyAny>>>
where N: IntoPyObject<'py, Target = PyString>,

Retrieve an attribute value, skipping the instance dictionary during the lookup but still binding the object to the instance.

This is useful when trying to resolve Python’s “magic” methods like __getitem__, which are looked up starting from the type object. This returns an Option as it is not typically a direct error for the special lookup to fail, as magic methods are optional in many situations in which they might be called.

To avoid repeated temporary allocations of Python strings, the intern! macro can be used to intern attr_name.

Trait Implementations§

Source§

impl<'py> Add for Borrowed<'_, 'py, PyComplex>

Available on neither Py_LIMITED_API nor PyPy nor GraalPy.
Source§

type Output = Bound<'py, PyComplex>

The resulting type after applying the + operator.
Source§

fn add(self, other: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<'a, 'py, T> BoundObject<'py, T> for Borrowed<'a, 'py, T>

Source§

type Any = Borrowed<'a, 'py, PyAny>

Type erased version of Self
Source§

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

Borrow this smart pointer.
Source§

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

Turns this smart pointer into an owned [Bound<'py, T>]
Source§

fn into_any(self) -> Self::Any

Upcast the target type of this smart pointer
Source§

fn into_ptr(self) -> *mut PyObject

Turn this smart pointer into a strong reference pointer
Source§

fn as_ptr(&self) -> *mut PyObject

Turn this smart pointer into a borrowed reference pointer
Source§

fn unbind(self) -> Py<T>

Turn this smart pointer into an owned Py<T>
Source§

impl<T> Clone for Borrowed<'_, '_, 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<T> Debug for Borrowed<'_, '_, T>

Source§

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

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

impl<'py, T> Deref for Borrowed<'_, 'py, T>

Source§

type Target = Bound<'py, T>

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<'py> Div for Borrowed<'_, 'py, PyComplex>

Available on neither Py_LIMITED_API nor PyPy nor GraalPy.
Source§

type Output = Bound<'py, PyComplex>

The resulting type after applying the / operator.
Source§

fn div(self, other: Self) -> Self::Output

Performs the / operation. 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<T> IntoPy<Py<PyAny>> for Borrowed<'_, '_, T>

Source§

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

👎Deprecated since 0.23.0: IntoPy is going to be replaced by IntoPyObject. See the migration guide (https://pyo3.rs/v0.23.0/migration) for more information.

Converts Py instance -> PyObject.

Source§

impl<'a, 'py, T> IntoPyObject<'py> for &Borrowed<'a, 'py, T>

Source§

type Target = T

The Python output type
Source§

type Output = Borrowed<'a, 'py, <&Borrowed<'a, 'py, T> as IntoPyObject<'py>>::Target>

The smart pointer type to use. Read more
Source§

type Error = Infallible

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

fn into_pyobject(self, _py: Python<'py>) -> Result<Self::Output, Self::Error>

Performs the conversion.
Source§

fn type_output() -> TypeInfo

Available on crate feature experimental-inspect only.
Extracts the type hint information for this type when it appears as a return value. Read more
Source§

#[doc(hidden)] fn owned_sequence_into_pyobject<I>( iter: I, py: Python<'py>, _: Token, ) -> Result<Bound<'py, PyAny>, PyErr>
where I: IntoIterator<Item = Self> + AsRef<[Self]>, I::IntoIter: ExactSizeIterator<Item = Self>,

Converts sequence of Self into a Python object. Used to specialize Vec<u8>, [u8; N] and SmallVec<[u8; N]> as a sequence of bytes into a bytes object.
Source§

#[doc(hidden)] fn borrowed_sequence_into_pyobject<I>( iter: I, py: Python<'py>, _: Token, ) -> Result<Bound<'py, PyAny>, PyErr>
where Self: Reference, I: IntoIterator<Item = Self> + AsRef<[<Self as Reference>::BaseType]>, I::IntoIter: ExactSizeIterator<Item = Self>,

Converts sequence of Self into a Python object. Used to specialize &[u8] and Cow<[u8]> as a sequence of bytes into a bytes object.
Source§

impl<'a, 'py, T> IntoPyObject<'py> for Borrowed<'a, 'py, T>

Source§

type Target = T

The Python output type
Source§

type Output = Borrowed<'a, 'py, <Borrowed<'a, 'py, T> as IntoPyObject<'py>>::Target>

The smart pointer type to use. Read more
Source§

type Error = Infallible

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

fn into_pyobject(self, _py: Python<'py>) -> Result<Self::Output, Self::Error>

Performs the conversion.
Source§

fn type_output() -> TypeInfo

Available on crate feature experimental-inspect only.
Extracts the type hint information for this type when it appears as a return value. Read more
Source§

#[doc(hidden)] fn owned_sequence_into_pyobject<I>( iter: I, py: Python<'py>, _: Token, ) -> Result<Bound<'py, PyAny>, PyErr>
where I: IntoIterator<Item = Self> + AsRef<[Self]>, I::IntoIter: ExactSizeIterator<Item = Self>,

Converts sequence of Self into a Python object. Used to specialize Vec<u8>, [u8; N] and SmallVec<[u8; N]> as a sequence of bytes into a bytes object.
Source§

impl<'py> Mul for Borrowed<'_, 'py, PyComplex>

Available on neither Py_LIMITED_API nor PyPy nor GraalPy.
Source§

type Output = Bound<'py, PyComplex>

The resulting type after applying the * operator.
Source§

fn mul(self, other: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl<'py> Neg for Borrowed<'_, 'py, PyComplex>

Available on neither Py_LIMITED_API nor PyPy nor GraalPy.
Source§

type Output = Bound<'py, PyComplex>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl PartialEq<&[u8]> for Borrowed<'_, '_, PyBytes>

Compares whether the Python bytes object is equal to the u8.

In some cases Python equality might be more appropriate; see the note on PyBytes.

Source§

fn eq(&self, other: &&[u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&bool> for Borrowed<'_, '_, PyBool>

Compare Borrowed<PyBool> with &bool

Source§

fn eq(&self, other: &&bool) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&f32> for Borrowed<'_, '_, PyFloat>

Source§

fn eq(&self, other: &&f32) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&f64> for Borrowed<'_, '_, PyFloat>

Source§

fn eq(&self, other: &&f64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<&str> for Borrowed<'_, '_, PyString>

Compares whether the data in the Python string is equal to the given UTF8.

In some cases Python equality might be more appropriate; see the note on PyString.

Source§

fn eq(&self, other: &&str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<[u8]> for Borrowed<'_, '_, PyBytes>

Compares whether the Python bytes object is equal to the u8.

In some cases Python equality might be more appropriate; see the note on PyBytes.

Source§

fn eq(&self, other: &[u8]) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Borrowed<'_, '_, PyBool>> for &bool

Compare &bool with Borrowed<PyBool>

Source§

fn eq(&self, other: &Borrowed<'_, '_, PyBool>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Borrowed<'_, '_, PyBool>> for bool

Compare bool with Borrowed<PyBool>

Source§

fn eq(&self, other: &Borrowed<'_, '_, PyBool>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Borrowed<'_, '_, PyBytes>> for &[u8]

Compares whether the Python bytes object is equal to the u8.

In some cases Python equality might be more appropriate; see the note on PyBytes.

Source§

fn eq(&self, other: &Borrowed<'_, '_, PyBytes>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Borrowed<'_, '_, PyBytes>> for [u8]

Compares whether the Python bytes object is equal to the u8.

In some cases Python equality might be more appropriate; see the note on PyBytes.

Source§

fn eq(&self, other: &Borrowed<'_, '_, PyBytes>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Borrowed<'_, '_, PyFloat>> for &f32

Source§

fn eq(&self, other: &Borrowed<'_, '_, PyFloat>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Borrowed<'_, '_, PyFloat>> for &f64

Source§

fn eq(&self, other: &Borrowed<'_, '_, PyFloat>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Borrowed<'_, '_, PyFloat>> for f32

Source§

fn eq(&self, other: &Borrowed<'_, '_, PyFloat>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Borrowed<'_, '_, PyFloat>> for f64

Source§

fn eq(&self, other: &Borrowed<'_, '_, PyFloat>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Borrowed<'_, '_, PyString>> for &str

Compares whether the data in the Python string is equal to the given UTF8.

In some cases Python equality might be more appropriate; see the note on PyString.

Source§

fn eq(&self, other: &Borrowed<'_, '_, PyString>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Borrowed<'_, '_, PyString>> for str

Compares whether the data in the Python string is equal to the given UTF8.

In some cases Python equality might be more appropriate; see the note on PyString.

Source§

fn eq(&self, other: &Borrowed<'_, '_, PyString>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<bool> for Borrowed<'_, '_, PyBool>

Compare Borrowed<PyBool> with bool

Source§

fn eq(&self, other: &bool) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<f32> for Borrowed<'_, '_, PyFloat>

Source§

fn eq(&self, other: &f32) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<f64> for Borrowed<'_, '_, PyFloat>

Source§

fn eq(&self, other: &f64) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<str> for Borrowed<'_, '_, PyString>

Compares whether the data in the Python string is equal to the given UTF8.

In some cases Python equality might be more appropriate; see the note on PyString.

Source§

fn eq(&self, other: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'py> Sub for Borrowed<'_, 'py, PyComplex>

Available on neither Py_LIMITED_API nor PyPy nor GraalPy.
Source§

type Output = Bound<'py, PyComplex>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Self::Output

Performs the - operation. Read more
Source§

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

Source§

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

👎Deprecated since 0.23.0: ToPyObject is going to be replaced by IntoPyObject. See the migration guide (https://pyo3.rs/v0.23.0/migration) for more information.

Converts Py instance -> PyObject.

Source§

impl<'py> WrapPyFunctionArg<'py, Bound<'py, PyCFunction>> for &Borrowed<'_, 'py, PyModule>

Source§

fn wrap_pyfunction( self, method_def: &PyMethodDef, ) -> PyResult<Bound<'py, PyCFunction>>

Source§

impl<'py> WrapPyFunctionArg<'py, Bound<'py, PyCFunction>> for Borrowed<'_, 'py, PyModule>

Source§

fn wrap_pyfunction( self, method_def: &PyMethodDef, ) -> PyResult<Bound<'py, PyCFunction>>

Source§

impl<T> Copy for Borrowed<'_, '_, T>

Source§

impl<T> Sealed for Borrowed<'_, '_, T>

Auto Trait Implementations§

§

impl<'a, 'py, T> Freeze for Borrowed<'a, 'py, T>

§

impl<'a, 'py, T> RefUnwindSafe for Borrowed<'a, 'py, T>
where T: RefUnwindSafe,

§

impl<'a, 'py, T> !Send for Borrowed<'a, 'py, T>

§

impl<'a, 'py, T> !Sync for Borrowed<'a, 'py, T>

§

impl<'a, 'py, T> Unpin for Borrowed<'a, 'py, T>

§

impl<'a, 'py, T> UnwindSafe for Borrowed<'a, 'py, T>
where T: RefUnwindSafe,

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> AssertNotZeroSized for T

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<'py, T> IntoPyCallbackOutput<'py, *mut PyObject> for T
where T: IntoPyObject<'py>,

Source§

impl<'py, T> IntoPyCallbackOutput<'py, Py<PyAny>> for T
where T: IntoPyObject<'py>,

Source§

fn convert(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>

Source§

impl<'py, T> IntoPyObjectExt<'py> for T
where T: IntoPyObject<'py>,

Source§

fn into_bound_py_any(self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>>

Converts self into an owned Python object, dropping type information.
Source§

fn into_py_any(self, py: Python<'py>) -> PyResult<Py<PyAny>>

Converts self into an owned Python object, dropping type information and unbinding it from the 'py lifetime.
Source§

fn into_pyobject_or_pyerr(self, py: Python<'py>) -> PyResult<Self::Output>

Converts self into a Python object. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
Available on non-bootstrap only.
The target type on which the method may be called.
Source§

impl<T> SizedTypeProperties for T

Source§

#[doc(hidden)] const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
Source§

#[doc(hidden)] const LAYOUT: Layout = _

🔬This is a nightly-only experimental API. (sized_type_properties)
Source§

impl<T> SomeWrap<T> for T

Source§

fn wrap(self) -> Option<T>

Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.
Source§

impl<T> Printable for T
where T: Copy + Debug,

Source§

impl<'py, T> PyO3GetField<'py> for T
where T: IntoPyObject<'py> + Clone,

Source§

impl<'py, T> Sealed for T
where T: IntoPyObject<'py>,

⚠️ Internal Docs ⚠️ Not Public API 👉 Official Docs Here