pub trait PyTryFrom<'v>: Sized + PyNativeType {
fn try_from<V>(value: V) -> Result<&'v Self, PyDowncastError<'v>>
where
V: Into<&'v PyAny>;
fn try_from_exact<V>(value: V) -> Result<&'v Self, PyDowncastError<'v>>
where
V: Into<&'v PyAny>;
unsafe fn try_from_unchecked<V>(value: V) -> &'v Self
where
V: Into<&'v PyAny>;
}
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
sourcefn try_from<V>(value: V) -> Result<&'v Self, PyDowncastError<'v>>where
V: Into<&'v PyAny>,
fn try_from<V>(value: V) -> Result<&'v Self, PyDowncastError<'v>>where
V: Into<&'v PyAny>,
Cast from a concrete Python object type to PyObject.
sourcefn try_from_exact<V>(value: V) -> Result<&'v Self, PyDowncastError<'v>>where
V: Into<&'v PyAny>,
fn try_from_exact<V>(value: V) -> Result<&'v Self, PyDowncastError<'v>>where
V: Into<&'v PyAny>,
Cast from a concrete Python object type to PyObject. With exact type check.