[][src]Trait pyo3::conversion::FromPyObject

pub trait FromPyObject<'source>: Sized {
    fn extract(ob: &'source PyAny) -> PyResult<Self>;
}

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

fn extract(ob: &'source PyAny) -> PyResult<Self>

Extracts Self from the source PyObject.

Loading content...

Implementations on Foreign Types

impl<'a, T> FromPyObject<'a> for Option<T> where
    T: FromPyObject<'a>, 
[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.

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]

impl<'source, K, V> FromPyObject<'source> for BTreeMap<K, V> where
    K: FromPyObject<'source> + Ord,
    V: FromPyObject<'source>, 
[src]

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]

impl<'a, T> FromPyObject<'a> for [T; 1] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 2] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 3] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 4] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 5] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 6] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 7] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 8] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 9] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 10] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 11] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 12] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 13] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 14] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 15] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 16] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 17] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 18] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 19] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 20] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 21] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 22] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 23] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 24] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 25] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 26] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 27] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 28] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 29] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 30] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 31] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for [T; 32] where
    T: Copy + Default + FromPyObject<'a>, 
[src]

impl<'a, T> FromPyObject<'a> for Vec<T> where
    T: FromPyObject<'a>, 
[src]

impl<'source, K, S> FromPyObject<'source> for HashSet<K, S> where
    K: FromPyObject<'source> + Eq + Hash,
    S: BuildHasher + Default
[src]

impl<'source, K> FromPyObject<'source> for BTreeSet<K> where
    K: FromPyObject<'source> + Ord
[src]

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]

fn extract(ob: &'a PyAny) -> PyResult<Self>[src]

Extracts Self from the source PyObject.

impl<'a, T> FromPyObject<'a> for &'a PyCell<T> where
    T: PyClass
[src]

impl<'a, T> FromPyObject<'a> for PyRef<'a, T> where
    T: PyClass
[src]

impl<'a, T> FromPyObject<'a> for PyRefMut<'a, T> where
    T: PyClass
[src]

impl<'a, T> FromPyObject<'a> for Py<T> where
    T: PyTypeInfo,
    &'a T::AsRefTarget: FromPyObject<'a>,
    T::AsRefTarget: 'a + AsPyPointer
[src]

fn extract(ob: &'a PyAny) -> PyResult<Self>[src]

Extracts Self from the source PyObject.

impl<'a, T> FromPyObject<'a> for T where
    T: PyClass + Clone
[src]

impl<'py> FromPyObject<'py> for &'py PyModule[src]

impl<'py> FromPyObject<'py> for &'py PyAny[src]

impl<'py> FromPyObject<'py> for &'py PyBool[src]

impl<'py> FromPyObject<'py> for &'py PyByteArray[src]

impl<'py> FromPyObject<'py> for &'py PyBytes[src]

impl<'py> FromPyObject<'py> for &'py PyComplex[src]

impl<'py> FromPyObject<'py> for &'py PyDate[src]

impl<'py> FromPyObject<'py> for &'py PyDateTime[src]

impl<'py> FromPyObject<'py> for &'py PyDelta[src]

impl<'py> FromPyObject<'py> for &'py PyDict[src]

impl<'py> FromPyObject<'py> for &'py PyFloat[src]

impl<'py> FromPyObject<'py> for &'py PyFrozenSet[src]

impl<'py> FromPyObject<'py> for &'py PyList[src]

impl<'py> FromPyObject<'py> for &'py PyLong[src]

impl<'py> FromPyObject<'py> for &'py PySequence[src]

impl<'py> FromPyObject<'py> for &'py PySet[src]

impl<'py> FromPyObject<'py> for &'py PySlice[src]

impl<'py> FromPyObject<'py> for &'py PyString[src]

impl<'py> FromPyObject<'py> for &'py PyTime[src]

impl<'py> FromPyObject<'py> for &'py PyTuple[src]

impl<'py> FromPyObject<'py> for &'py PyType[src]

impl<'py> FromPyObject<'py> for &'py PyTzInfo[src]

impl<'source, T: Element> FromPyObject<'source> for PyBuffer<T>[src]

Loading content...