Trait pyo3::conversion::FromPyObject
source · [−]Expand description
FromPyObject
is implemented by various types that can be extracted from
a Python object reference.
Normal usage is through the helper methods Py::extract
or PyAny::extract
:
let obj: Py<PyAny> = ...;
let value: &TargetType = obj.extract(py)?;
let any: &PyAny = ...;
let value: &TargetType = any.extract()?;
Note: depending on the implementation, the lifetime of the extracted result may
depend on the lifetime of the obj
or the prepared
variable.
For example, when extracting &str
from a Python byte string, the resulting string slice will
point to the existing string data (lifetime: 'source
).
On the other hand, when extracting &str
from a Python Unicode string, the preparation step
will convert the string to UTF-8, and the resulting string slice will have lifetime 'prepared
.
Since which case applies depends on the runtime type of the Python object,
both the obj
and prepared
variables must outlive the resulting string slice.
The trait’s conversion method takes a &PyAny
argument but is called
FromPyObject
for historical reasons.
Required methods
Implementations on Foreign Types
sourceimpl<'a, T> FromPyObject<'a> for Option<T> where
T: FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for Option<T> where
T: FromPyObject<'a>,
sourceimpl<'a, T, const N: usize> FromPyObject<'a> for [T; N] where
T: FromPyObject<'a>,
impl<'a, T, const N: usize> FromPyObject<'a> for [T; N] where
T: FromPyObject<'a>,
sourceimpl<'source, K, V, S> FromPyObject<'source> for HashMap<K, V, S> where
K: FromPyObject<'source> + Eq + Hash,
V: FromPyObject<'source>,
S: BuildHasher + Default,
impl<'source, K, V, S> FromPyObject<'source> for HashMap<K, V, S> where
K: FromPyObject<'source> + Eq + Hash,
V: FromPyObject<'source>,
S: BuildHasher + Default,
sourceimpl<'source, K, S> FromPyObject<'source> for HashSet<K, S> where
K: FromPyObject<'source> + Eq + Hash,
S: BuildHasher + Default,
impl<'source, K, S> FromPyObject<'source> for HashSet<K, S> where
K: FromPyObject<'source> + Eq + Hash,
S: BuildHasher + Default,
sourceimpl<'source, K, V, S> FromPyObject<'source> for IndexMap<K, V, S> where
K: FromPyObject<'source> + Eq + Hash,
V: FromPyObject<'source>,
S: BuildHasher + Default,
impl<'source, K, V, S> FromPyObject<'source> for IndexMap<K, V, S> where
K: FromPyObject<'source> + Eq + Hash,
V: FromPyObject<'source>,
S: BuildHasher + Default,
sourceimpl<'source> FromPyObject<'source> for BigUint
This is supported on crate feature num-bigint
only.
impl<'source> FromPyObject<'source> for BigUint
num-bigint
only.sourceimpl<'source> FromPyObject<'source> for BigInt
This is supported on crate feature num-bigint
only.
impl<'source> FromPyObject<'source> for BigInt
num-bigint
only.sourceimpl<'source> FromPyObject<'source> for Complex<f32>
This is supported on crate feature num-complex
only.
impl<'source> FromPyObject<'source> for Complex<f32>
num-complex
only.sourceimpl<'source> FromPyObject<'source> for Complex<f64>
This is supported on crate feature num-complex
only.
impl<'source> FromPyObject<'source> for Complex<f64>
num-complex
only.sourceimpl<'source> FromPyObject<'source> for bool
impl<'source> FromPyObject<'source> for bool
Converts a Python bool
to a Rust bool
.
Fails with TypeError
if the input is not a Python bool
.
sourceimpl<'source, K, V, S> FromPyObject<'source> for HashMap<K, V, S> where
K: FromPyObject<'source> + Eq + Hash,
V: FromPyObject<'source>,
S: BuildHasher + Default,
impl<'source, K, V, S> FromPyObject<'source> for HashMap<K, V, S> where
K: FromPyObject<'source> + Eq + Hash,
V: FromPyObject<'source>,
S: BuildHasher + Default,
sourceimpl<'source, K, V> FromPyObject<'source> for BTreeMap<K, V> where
K: FromPyObject<'source> + Ord,
V: FromPyObject<'source>,
impl<'source, K, V> FromPyObject<'source> for BTreeMap<K, V> where
K: FromPyObject<'source> + Ord,
V: FromPyObject<'source>,
sourceimpl<'source> FromPyObject<'source> for f64
impl<'source> FromPyObject<'source> for f64
sourceimpl<'source> FromPyObject<'source> for f32
impl<'source> FromPyObject<'source> for f32
sourceimpl<'source> FromPyObject<'source> for i8
impl<'source> FromPyObject<'source> for i8
sourceimpl<'source> FromPyObject<'source> for u8
impl<'source> FromPyObject<'source> for u8
sourceimpl<'source> FromPyObject<'source> for i16
impl<'source> FromPyObject<'source> for i16
sourceimpl<'source> FromPyObject<'source> for u16
impl<'source> FromPyObject<'source> for u16
sourceimpl<'source> FromPyObject<'source> for i32
impl<'source> FromPyObject<'source> for i32
sourceimpl<'source> FromPyObject<'source> for u32
impl<'source> FromPyObject<'source> for u32
sourceimpl<'source> FromPyObject<'source> for i64
impl<'source> FromPyObject<'source> for i64
sourceimpl<'source> FromPyObject<'source> for isize
impl<'source> FromPyObject<'source> for isize
sourceimpl<'source> FromPyObject<'source> for usize
impl<'source> FromPyObject<'source> for usize
sourceimpl<'source> FromPyObject<'source> for u64
impl<'source> FromPyObject<'source> for u64
sourceimpl<'source> FromPyObject<'source> for i128
impl<'source> FromPyObject<'source> for i128
sourceimpl<'source> FromPyObject<'source> for u128
impl<'source> FromPyObject<'source> for u128
sourceimpl<'a, T> FromPyObject<'a> for Vec<T> where
T: FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for Vec<T> where
T: FromPyObject<'a>,
sourceimpl<'source, K, S> FromPyObject<'source> for HashSet<K, S> where
K: FromPyObject<'source> + Eq + Hash,
S: BuildHasher + Default,
impl<'source, K, S> FromPyObject<'source> for HashSet<K, S> where
K: FromPyObject<'source> + Eq + Hash,
S: BuildHasher + Default,
sourceimpl<'source, K> FromPyObject<'source> for BTreeSet<K> where
K: FromPyObject<'source> + Ord,
impl<'source, K> FromPyObject<'source> for BTreeSet<K> where
K: FromPyObject<'source> + Ord,
sourceimpl<'source> FromPyObject<'source> for &'source str
impl<'source> FromPyObject<'source> for &'source str
Allows extracting strings from Python objects.
Accepts Python str
and unicode
objects.
sourceimpl FromPyObject<'_> for String
impl FromPyObject<'_> for String
Allows extracting strings from Python objects.
Accepts Python str
and unicode
objects.