Trait cpython::FromPyObject
[−]
[src]
pub trait FromPyObject<'source>: Sized { fn extract(py: Python, obj: &'source PyObject) -> PyResult<Self>; }
FromPyObject is implemented by various types that can be extracted from a Python object.
Normal usage is through the PyObject::extract helper method:
let obj: PyObject = ...; let value = try!(obj.extract::<TargetType>(py));
TODO: update this documentation
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(py: Python, obj: &'source PyObject) -> PyResult<Self>
Extracts Self from the source PyObject.
Implementations on Foreign Types
impl<'source, T> FromPyObject<'source> for Option<T> where
T: FromPyObject<'source>, [src]
T: FromPyObject<'source>,
impl<'source> FromPyObject<'source> for Cow<'source, str>[src]
Allows extracting strings from Python objects.
Accepts Python str and unicode objects.
In Python 2.7, str is expected to be UTF-8 encoded.
impl<'source> FromPyObject<'source> for String[src]
Allows extracting strings from Python objects.
Accepts Python str and unicode objects.
In Python 2.7, str is expected to be UTF-8 encoded.
impl<'source> FromPyObject<'source> for bool[src]
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]
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 f64[src]
impl<'source> FromPyObject<'source> for f32[src]
impl<'source, T> FromPyObject<'source> for Vec<T> where
T: FromPyObject<'a>, [src]
T: FromPyObject<'a>,
Implementors
impl<'source> FromPyObject<'source> for PyObjectimpl<'source> FromPyObject<'source> for &'source PyObjectimpl<'source> FromPyObject<'source> for PyTypeimpl<'source> FromPyObject<'source> for &'source PyTypeimpl<'source> FromPyObject<'source> for PyModuleimpl<'source> FromPyObject<'source> for &'source PyModuleimpl<'source> FromPyObject<'source> for PyStringimpl<'source> FromPyObject<'source> for &'source PyStringimpl<'source> FromPyObject<'source> for PyBytesimpl<'source> FromPyObject<'source> for &'source PyBytesimpl<'source> FromPyObject<'source> for PyDictimpl<'source> FromPyObject<'source> for &'source PyDictimpl<'source> FromPyObject<'source> for PyBoolimpl<'source> FromPyObject<'source> for &'source PyBoolimpl<'source> FromPyObject<'source> for PyTupleimpl<'source> FromPyObject<'source> for &'source PyTupleimpl<'source> FromPyObject<'source> for NoArgsimpl<'source> FromPyObject<'source> for PyListimpl<'source> FromPyObject<'source> for &'source PyListimpl<'source> FromPyObject<'source> for PyLongimpl<'source> FromPyObject<'source> for &'source PyLongimpl<'source> FromPyObject<'source> for PyFloatimpl<'source> FromPyObject<'source> for &'source PyFloatimpl<'source> FromPyObject<'source> for PySequenceimpl<'source> FromPyObject<'source> for &'source PySequenceimpl<'source> FromPyObject<'source> for BaseExceptionimpl<'source> FromPyObject<'source> for &'source BaseExceptionimpl<'source> FromPyObject<'source> for Exceptionimpl<'source> FromPyObject<'source> for &'source Exceptionimpl<'source> FromPyObject<'source> for LookupErrorimpl<'source> FromPyObject<'source> for &'source LookupErrorimpl<'source> FromPyObject<'source> for AssertionErrorimpl<'source> FromPyObject<'source> for &'source AssertionErrorimpl<'source> FromPyObject<'source> for AttributeErrorimpl<'source> FromPyObject<'source> for &'source AttributeErrorimpl<'source> FromPyObject<'source> for EOFErrorimpl<'source> FromPyObject<'source> for &'source EOFErrorimpl<'source> FromPyObject<'source> for EnvironmentErrorimpl<'source> FromPyObject<'source> for &'source EnvironmentErrorimpl<'source> FromPyObject<'source> for FloatingPointErrorimpl<'source> FromPyObject<'source> for &'source FloatingPointErrorimpl<'source> FromPyObject<'source> for IOErrorimpl<'source> FromPyObject<'source> for &'source IOErrorimpl<'source> FromPyObject<'source> for ImportErrorimpl<'source> FromPyObject<'source> for &'source ImportErrorimpl<'source> FromPyObject<'source> for IndexErrorimpl<'source> FromPyObject<'source> for &'source IndexErrorimpl<'source> FromPyObject<'source> for KeyErrorimpl<'source> FromPyObject<'source> for &'source KeyErrorimpl<'source> FromPyObject<'source> for KeyboardInterruptimpl<'source> FromPyObject<'source> for &'source KeyboardInterruptimpl<'source> FromPyObject<'source> for MemoryErrorimpl<'source> FromPyObject<'source> for &'source MemoryErrorimpl<'source> FromPyObject<'source> for NameErrorimpl<'source> FromPyObject<'source> for &'source NameErrorimpl<'source> FromPyObject<'source> for NotImplementedErrorimpl<'source> FromPyObject<'source> for &'source NotImplementedErrorimpl<'source> FromPyObject<'source> for OSErrorimpl<'source> FromPyObject<'source> for &'source OSErrorimpl<'source> FromPyObject<'source> for OverflowErrorimpl<'source> FromPyObject<'source> for &'source OverflowErrorimpl<'source> FromPyObject<'source> for ReferenceErrorimpl<'source> FromPyObject<'source> for &'source ReferenceErrorimpl<'source> FromPyObject<'source> for RuntimeErrorimpl<'source> FromPyObject<'source> for &'source RuntimeErrorimpl<'source> FromPyObject<'source> for SyntaxErrorimpl<'source> FromPyObject<'source> for &'source SyntaxErrorimpl<'source> FromPyObject<'source> for SystemErrorimpl<'source> FromPyObject<'source> for &'source SystemErrorimpl<'source> FromPyObject<'source> for SystemExitimpl<'source> FromPyObject<'source> for &'source SystemExitimpl<'source> FromPyObject<'source> for TypeErrorimpl<'source> FromPyObject<'source> for &'source TypeErrorimpl<'source> FromPyObject<'source> for ValueErrorimpl<'source> FromPyObject<'source> for &'source ValueErrorimpl<'source> FromPyObject<'source> for ZeroDivisionErrorimpl<'source> FromPyObject<'source> for &'source ZeroDivisionErrorimpl<'source> FromPyObject<'source> for BufferErrorimpl<'source> FromPyObject<'source> for &'source BufferErrorimpl<'source> FromPyObject<'source> for UnicodeDecodeErrorimpl<'source> FromPyObject<'source> for &'source UnicodeDecodeErrorimpl<'source> FromPyObject<'source> for UnicodeEncodeErrorimpl<'source> FromPyObject<'source> for &'source UnicodeEncodeErrorimpl<'source> FromPyObject<'source> for UnicodeTranslateErrorimpl<'source> FromPyObject<'source> for &'source UnicodeTranslateError