Trait pyo3::conversion::PyTryFrom [−][src]
pub trait PyTryFrom<'v>: Sized + PyNativeType {
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;
}
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
Cast from a concrete Python object type to PyObject.
fn try_from_exact<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>>
Cast from a concrete Python object type to PyObject. With exact type check.