[][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 Py::extract or PyAny::extract:

This example is not tested
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

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> FromPyObject<'source> for Complex<f32>[src]

impl<'source> FromPyObject<'source> for Complex<f64>[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<'source> FromPyObject<'source> for BigUint[src]

impl<'source> FromPyObject<'source> for BigInt[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 &'source 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, 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 CancelledError[src]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

impl<'py> FromPyObject<'py> for &'py PanicException[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 PyCFunction[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 PyFunction[src]

impl<'py> FromPyObject<'py> for &'py PyIterator[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...