[−][src]Trait pyo3::prelude::FromPyObject
FromPyObject
is implemented by various types that can be extracted from
a Python object reference.
Normal usage is through the PyObject::extract
helper method:
let value: &TargetType = obj.extract(py)?;
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 only which of these cases 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.
Required methods
fn extract(ob: &'source PyObjectRef) -> PyResult<Self>
Extracts Self
from the source PyObject
.
Implementations on Foreign Types
impl<'a, T> FromPyObject<'a> for &'a T where
T: PyTryFrom<'a>,
[src]
T: PyTryFrom<'a>,
Extract reference to instance from PyObject
fn extract(ob: &'a PyObjectRef) -> PyResult<&'a T>
[src]
impl<'a, T> FromPyObject<'a> for &'a mut T where
T: PyTryFrom<'a>,
[src]
T: PyTryFrom<'a>,
Extract mutable reference to instance from PyObject
fn extract(ob: &'a PyObjectRef) -> PyResult<&'a mut T>
[src]
impl<'a, T> FromPyObject<'a> for Option<T> where
T: FromPyObject<'a>,
[src]
T: FromPyObject<'a>,
fn extract(obj: &'a PyObjectRef) -> PyResult<Self>
[src]
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
.
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for f64
[src]
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for f32
[src]
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'a, T> FromPyObject<'a> for Vec<T> where
T: FromPyObject<'a>,
[src]
T: FromPyObject<'a>,
fn extract(obj: &'a PyObjectRef) -> PyResult<Self>
[src]
impl<'source, T> FromPyObject<'source> for Vec<T> where
T: FromPyObject<'a> + Element + Copy,
[src]
T: FromPyObject<'a> + Element + Copy,
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for Cow<'source, str>
[src]
Allows extracting strings from Python objects.
Accepts Python str
and unicode
objects.
fn extract(ob: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'a> FromPyObject<'a> for &'a str
[src]
Allows extracting strings from Python objects.
Accepts Python str
and unicode
objects.
fn extract(ob: &'a PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for String
[src]
Allows extracting strings from Python objects.
Accepts Python str
and unicode
objects.
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'s, A: FromPyObject<'s>> FromPyObject<'s> for (A,)
[src]
fn extract(obj: &'s PyObjectRef) -> PyResult<Self>
[src]
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>> FromPyObject<'s> for (A, B)
[src]
fn extract(obj: &'s PyObjectRef) -> PyResult<Self>
[src]
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>, C: FromPyObject<'s>> FromPyObject<'s> for (A, B, C)
[src]
fn extract(obj: &'s PyObjectRef) -> PyResult<Self>
[src]
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>, C: FromPyObject<'s>, D: FromPyObject<'s>> FromPyObject<'s> for (A, B, C, D)
[src]
fn extract(obj: &'s PyObjectRef) -> PyResult<Self>
[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]
fn extract(obj: &'s PyObjectRef) -> PyResult<Self>
[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]
fn extract(obj: &'s PyObjectRef) -> PyResult<Self>
[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]
fn extract(obj: &'s PyObjectRef) -> PyResult<Self>
[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]
fn extract(obj: &'s PyObjectRef) -> PyResult<Self>
[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]
fn extract(obj: &'s PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for i8
[src]
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for u8
[src]
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for i16
[src]
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for u16
[src]
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for i32
[src]
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for u32
[src]
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for i64
[src]
fn extract(ob: &'source PyObjectRef) -> PyResult<i64>
[src]
impl<'source> FromPyObject<'source> for isize
[src]
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for usize
[src]
fn extract(obj: &'source PyObjectRef) -> PyResult<Self>
[src]
impl<'source> FromPyObject<'source> for u64
[src]
fn extract(ob: &'source PyObjectRef) -> PyResult<u64>
[src]
impl<'source> FromPyObject<'source> for i128
[src]
fn extract(ob: &'source PyObjectRef) -> PyResult<i128>
[src]
impl<'source> FromPyObject<'source> for u128
[src]
fn extract(ob: &'source PyObjectRef) -> PyResult<u128>
[src]
Implementors
impl<'a> FromPyObject<'a> for PyObject
[src]
fn extract(ob: &'a PyObjectRef) -> PyResult<Self>
[src]
Extracts Self
from the source PyObject
.
impl<'a, T> FromPyObject<'a> for Py<T> where
T: ToPyPointer,
&'a T: 'a + FromPyObject<'a>,
[src]
T: ToPyPointer,
&'a T: 'a + FromPyObject<'a>,
fn extract(ob: &'a PyObjectRef) -> PyResult<Self>
[src]
Extracts Self
from the source PyObject
.