pub trait PyTryFrom<'v>: Sized + PyNativeType {
    // Required methods
    fn try_from<V: Into<&'v PyAny>>(
        value: V
    ) -> Result<&'v Self, PyDowncastError<'v>>;
    fn try_from_exact<V: Into<&'v PyAny>>(
        value: V
    ) -> Result<&'v Self, PyDowncastError<'v>>;
    unsafe fn try_from_unchecked<V: Into<&'v PyAny>>(value: V) -> &'v Self;
}
👎Deprecated since 0.21.0
Expand description

Trait implemented by Python object types that allow a checked downcast. If T implements PyTryFrom, we can convert &PyAny to &T.

This trait is similar to std::convert::TryFrom

Required Methods§

source

fn try_from<V: Into<&'v PyAny>>( value: V ) -> Result<&'v Self, PyDowncastError<'v>>

👎Deprecated since 0.21.0: use value.downcast::<T>() instead of T::try_from(value)

Cast from a concrete Python object type to PyObject.

source

fn try_from_exact<V: Into<&'v PyAny>>( value: V ) -> Result<&'v Self, PyDowncastError<'v>>

👎Deprecated since 0.21.0: use value.downcast_exact::<T>() instead of T::try_from_exact(value)

Cast from a concrete Python object type to PyObject. With exact type check.

source

unsafe fn try_from_unchecked<V: Into<&'v PyAny>>(value: V) -> &'v Self

👎Deprecated since 0.21.0: use value.downcast_unchecked::<T>() instead of T::try_from_unchecked(value)

Cast a PyAny to a specific type of PyObject. The caller must have already verified the reference is for this type.

§Safety

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

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<'v> PyTryFrom<'v> for PyIterator

source§

impl<'v> PyTryFrom<'v> for PyMapping

source§

impl<'v> PyTryFrom<'v> for PySequence

source§

impl<'v, T> PyTryFrom<'v> for PyCell<T>
where T: 'v + PyClass,

source§

impl<'v, T> PyTryFrom<'v> for T
where T: PyTypeInfo<AsRefTarget = Self> + PyNativeType,