[−][src]Trait pyo3::conversion::FromPyObject
FromPyObject
is implemented by various types that can be extracted from
a Python object reference.
Normal usage is through the helper methods PyObject::extract
or
PyAny::extract
:
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.
In cases where the result does not depend on the 'prepared
lifetime,
the inherent method PyObject::extract()
can be used.
The trait's conversion method takes a &PyAny
argument but is called
FromPyObject
for historical reasons.
Required methods
Loading content...Implementations on Foreign Types
impl<'a, T> FromPyObject<'a> for Option<T> where
T: FromPyObject<'a>,
[src]
T: FromPyObject<'a>,
impl<'source> FromPyObject<'source> for bool
[src]
Converts a Python bool
to a Rust bool
.
Fails with TypeError
if the input is not a Python bool
.
impl<'a> FromPyObject<'a> for &'a [u8]
[src]
impl<'source, K, V, S> FromPyObject<'source> for HashMap<K, V, S> where
K: FromPyObject<'source> + Eq + Hash,
V: FromPyObject<'source>,
S: BuildHasher + Default,
[src]
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>,
[src]
K: FromPyObject<'source> + Ord,
V: FromPyObject<'source>,
impl<'source> FromPyObject<'source> for f64
[src]
impl<'source> FromPyObject<'source> for f32
[src]
impl<'source> FromPyObject<'source> for i8
[src]
impl<'source> FromPyObject<'source> for u8
[src]
impl<'source> FromPyObject<'source> for i16
[src]
impl<'source> FromPyObject<'source> for u16
[src]
impl<'source> FromPyObject<'source> for i32
[src]
impl<'source> FromPyObject<'source> for u32
[src]
impl<'source> FromPyObject<'source> for i64
[src]
impl<'source> FromPyObject<'source> for isize
[src]
impl<'source> FromPyObject<'source> for usize
[src]
impl<'source> FromPyObject<'source> for u64
[src]
impl<'source> FromPyObject<'source> for i128
[src]
impl<'source> FromPyObject<'source> for u128
[src]
impl<'a, T> FromPyObject<'a> for [T; 0] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 1] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 2] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 3] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 4] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 5] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 6] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 7] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 8] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 9] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 10] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 11] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 12] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 13] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 14] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 15] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 16] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 17] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 18] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 19] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 20] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 21] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 22] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 23] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 24] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 25] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 26] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 27] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 28] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 29] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 30] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 31] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for [T; 32] where
T: Copy + Default + FromPyObject<'a>,
[src]
T: Copy + Default + FromPyObject<'a>,
impl<'a, T> FromPyObject<'a> for Vec<T> where
T: FromPyObject<'a>,
[src]
T: FromPyObject<'a>,
impl<'source, K, S> FromPyObject<'source> for HashSet<K, S> where
K: FromPyObject<'source> + Eq + Hash,
S: BuildHasher + Default,
[src]
K: FromPyObject<'source> + Eq + Hash,
S: BuildHasher + Default,
impl<'source, K> FromPyObject<'source> for BTreeSet<K> where
K: FromPyObject<'source> + Ord,
[src]
K: FromPyObject<'source> + Ord,
impl<'source> FromPyObject<'source> for Cow<'source, str>
[src]
Allows extracting strings from Python objects.
Accepts Python str
and unicode
objects.
impl<'a> FromPyObject<'a> for &'a str
[src]
Allows extracting strings from Python objects.
Accepts Python str
and unicode
objects.
impl<'source> FromPyObject<'source> for String
[src]
Allows extracting strings from Python objects.
Accepts Python str
and unicode
objects.
impl<'s, A: FromPyObject<'s>> FromPyObject<'s> for (A,)
[src]
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>> FromPyObject<'s> for (A, B)
[src]
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>, C: FromPyObject<'s>> FromPyObject<'s> for (A, B, C)
[src]
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>, C: FromPyObject<'s>, D: FromPyObject<'s>> FromPyObject<'s> for (A, B, C, D)
[src]
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>, C: FromPyObject<'s>, D: FromPyObject<'s>, E: FromPyObject<'s>> FromPyObject<'s> for (A, B, C, D, E)
[src]
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>, C: FromPyObject<'s>, D: FromPyObject<'s>, E: FromPyObject<'s>, F: FromPyObject<'s>> FromPyObject<'s> for (A, B, C, D, E, F)
[src]
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>, C: FromPyObject<'s>, D: FromPyObject<'s>, E: FromPyObject<'s>, F: FromPyObject<'s>, G: FromPyObject<'s>> FromPyObject<'s> for (A, B, C, D, E, F, G)
[src]
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>, C: FromPyObject<'s>, D: FromPyObject<'s>, E: FromPyObject<'s>, F: FromPyObject<'s>, G: FromPyObject<'s>, H: FromPyObject<'s>> FromPyObject<'s> for (A, B, C, D, E, F, G, H)
[src]
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>, C: FromPyObject<'s>, D: FromPyObject<'s>, E: FromPyObject<'s>, F: FromPyObject<'s>, G: FromPyObject<'s>, H: FromPyObject<'s>, I: FromPyObject<'s>> FromPyObject<'s> for (A, B, C, D, E, F, G, H, I)
[src]
Loading content...Implementors
impl<'a> FromPyObject<'a> for PyObject
[src]
impl<'a, T> FromPyObject<'a> for &'a PyCell<T> where
T: PyClass,
[src]
T: PyClass,
impl<'a, T> FromPyObject<'a> for PyRef<'a, T> where
T: PyClass,
[src]
T: PyClass,
impl<'a, T> FromPyObject<'a> for PyRefMut<'a, T> where
T: PyClass,
[src]
T: PyClass,
impl<'a, T> FromPyObject<'a> for Py<T> where
T: PyTypeInfo,
&'a T::AsRefTarget: FromPyObject<'a>,
T::AsRefTarget: 'a + AsPyPointer,
[src]
T: PyTypeInfo,
&'a T::AsRefTarget: FromPyObject<'a>,
T::AsRefTarget: 'a + AsPyPointer,
impl<'a, T> FromPyObject<'a> for T where
T: PyClass + Clone,
[src]
T: PyClass + Clone,