Trait pyo3::conversion::FromPyObject [−][src]
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
impl<'source, K, V, S> FromPyObject<'source> for IndexMap<K, V, S> where
K: FromPyObject<'source> + Eq + Hash,
V: FromPyObject<'source>,
S: BuildHasher + Default,
This is supported on crate feature indexmap
only.
impl<'source, K, V, S> FromPyObject<'source> for IndexMap<K, V, S> where
K: FromPyObject<'source> + Eq + Hash,
V: FromPyObject<'source>,
S: BuildHasher + Default,
indexmap
only.Converts a Python bool
to a Rust bool
.
Fails with TypeError
if the input is not a Python bool
.
impl<'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,
impl<'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>,
impl<'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,
impl<'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,
impl<'source, K, S> FromPyObject<'source> for HashSet<K, S> where
K: FromPyObject<'source> + Eq + Hash,
S: BuildHasher + Default,
This is supported on crate feature hashbrown
only.
impl<'source, K, S> FromPyObject<'source> for HashSet<K, S> where
K: FromPyObject<'source> + Eq + Hash,
S: BuildHasher + Default,
hashbrown
only.Allows extracting strings from Python objects.
Accepts Python str
and unicode
objects.
Allows extracting strings from Python objects.
Accepts Python str
and unicode
objects.
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>, T7: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6, T7)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>, T7: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6, T7)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>, T7: FromPyObject<'s>, T8: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6, T7, T8)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>, T7: FromPyObject<'s>, T8: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6, T7, T8)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>, T7: FromPyObject<'s>, T8: FromPyObject<'s>, T9: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>, T7: FromPyObject<'s>, T8: FromPyObject<'s>, T9: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>, T7: FromPyObject<'s>, T8: FromPyObject<'s>, T9: FromPyObject<'s>, T10: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>, T7: FromPyObject<'s>, T8: FromPyObject<'s>, T9: FromPyObject<'s>, T10: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>, T7: FromPyObject<'s>, T8: FromPyObject<'s>, T9: FromPyObject<'s>, T10: FromPyObject<'s>, T11: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
impl<'s, T0: FromPyObject<'s>, T1: FromPyObject<'s>, T2: FromPyObject<'s>, T3: FromPyObject<'s>, T4: FromPyObject<'s>, T5: FromPyObject<'s>, T6: FromPyObject<'s>, T7: FromPyObject<'s>, T8: FromPyObject<'s>, T9: FromPyObject<'s>, T10: FromPyObject<'s>, T11: FromPyObject<'s>> FromPyObject<'s> for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
impl<'source> FromPyObject<'source> for BigUint
This is supported on crate feature num-bigint
and neither Py_LIMITED_API
nor PyPy
only.
impl<'source> FromPyObject<'source> for BigUint
num-bigint
and neither Py_LIMITED_API
nor PyPy
only.impl<'source> FromPyObject<'source> for BigInt
This is supported on crate feature num-bigint
and neither Py_LIMITED_API
nor PyPy
only.
impl<'source> FromPyObject<'source> for BigInt
num-bigint
and neither Py_LIMITED_API
nor PyPy
only.impl<'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.impl<'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.Implementors
impl<'a, T> FromPyObject<'a> for Py<T> where
T: PyTypeInfo,
&'a T::AsRefTarget: FromPyObject<'a>,
T::AsRefTarget: 'a + AsPyPointer,
impl<'source, T: Element> FromPyObject<'source> for PyBuffer<T>
Py_LIMITED_API
only.