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
.
Implementors
impl<'source> FromPyObject<'source> for PyObject
impl<'source> FromPyObject<'source> for &'source PyObject
impl<'source, T> FromPyObject<'source> for Option<T> where
T: FromPyObject<'source>,impl<'source> FromPyObject<'source> for PyType
impl<'source> FromPyObject<'source> for &'source PyType
impl<'source> FromPyObject<'source> for PyModule
impl<'source> FromPyObject<'source> for &'source PyModule
impl<'source> FromPyObject<'source> for PyString
impl<'source> FromPyObject<'source> for &'source PyString
impl<'source> FromPyObject<'source> for PyBytes
impl<'source> FromPyObject<'source> for &'source PyBytes
impl<'source> FromPyObject<'source> for Cow<'source, str>
impl<'source> FromPyObject<'source> for String
impl<'source> FromPyObject<'source> for PyDict
impl<'source> FromPyObject<'source> for &'source PyDict
impl<'source> FromPyObject<'source> for PyBool
impl<'source> FromPyObject<'source> for &'source PyBool
impl<'source> FromPyObject<'source> for bool
impl<'source> FromPyObject<'source> for PyTuple
impl<'source> FromPyObject<'source> for &'source PyTuple
impl<'s, A: FromPyObject<'s>> FromPyObject<'s> for (A,)
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>> FromPyObject<'s> for (A, B)
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>, C: FromPyObject<'s>> FromPyObject<'s> for (A, B, C)
impl<'s, A: FromPyObject<'s>, B: FromPyObject<'s>, C: FromPyObject<'s>, D: FromPyObject<'s>> FromPyObject<'s> for (A, B, C, D)
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)
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)
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)
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)
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)
impl<'source> FromPyObject<'source> for NoArgs
impl<'source> FromPyObject<'source> for PyList
impl<'source> FromPyObject<'source> for &'source PyList
impl<'source, T> FromPyObject<'source> for Vec<T> where
T: FromPyObject<'a>,impl<'source> FromPyObject<'source> for PyLong
impl<'source> FromPyObject<'source> for &'source PyLong
impl<'source> FromPyObject<'source> for PyFloat
impl<'source> FromPyObject<'source> for &'source PyFloat
impl<'source> FromPyObject<'source> for i8
impl<'source> FromPyObject<'source> for u8
impl<'source> FromPyObject<'source> for i16
impl<'source> FromPyObject<'source> for u16
impl<'source> FromPyObject<'source> for i32
impl<'source> FromPyObject<'source> for u32
impl<'source> FromPyObject<'source> for i64
impl<'source> FromPyObject<'source> for isize
impl<'source> FromPyObject<'source> for usize
impl<'source> FromPyObject<'source> for u64
impl<'source> FromPyObject<'source> for f64
impl<'source> FromPyObject<'source> for f32
impl<'source> FromPyObject<'source> for PySequence
impl<'source> FromPyObject<'source> for &'source PySequence
impl<'source> FromPyObject<'source> for BaseException
impl<'source> FromPyObject<'source> for &'source BaseException
impl<'source> FromPyObject<'source> for Exception
impl<'source> FromPyObject<'source> for &'source Exception
impl<'source> FromPyObject<'source> for LookupError
impl<'source> FromPyObject<'source> for &'source LookupError
impl<'source> FromPyObject<'source> for AssertionError
impl<'source> FromPyObject<'source> for &'source AssertionError
impl<'source> FromPyObject<'source> for AttributeError
impl<'source> FromPyObject<'source> for &'source AttributeError
impl<'source> FromPyObject<'source> for EOFError
impl<'source> FromPyObject<'source> for &'source EOFError
impl<'source> FromPyObject<'source> for EnvironmentError
impl<'source> FromPyObject<'source> for &'source EnvironmentError
impl<'source> FromPyObject<'source> for FloatingPointError
impl<'source> FromPyObject<'source> for &'source FloatingPointError
impl<'source> FromPyObject<'source> for IOError
impl<'source> FromPyObject<'source> for &'source IOError
impl<'source> FromPyObject<'source> for ImportError
impl<'source> FromPyObject<'source> for &'source ImportError
impl<'source> FromPyObject<'source> for IndexError
impl<'source> FromPyObject<'source> for &'source IndexError
impl<'source> FromPyObject<'source> for KeyError
impl<'source> FromPyObject<'source> for &'source KeyError
impl<'source> FromPyObject<'source> for KeyboardInterrupt
impl<'source> FromPyObject<'source> for &'source KeyboardInterrupt
impl<'source> FromPyObject<'source> for MemoryError
impl<'source> FromPyObject<'source> for &'source MemoryError
impl<'source> FromPyObject<'source> for NameError
impl<'source> FromPyObject<'source> for &'source NameError
impl<'source> FromPyObject<'source> for NotImplementedError
impl<'source> FromPyObject<'source> for &'source NotImplementedError
impl<'source> FromPyObject<'source> for OSError
impl<'source> FromPyObject<'source> for &'source OSError
impl<'source> FromPyObject<'source> for OverflowError
impl<'source> FromPyObject<'source> for &'source OverflowError
impl<'source> FromPyObject<'source> for ReferenceError
impl<'source> FromPyObject<'source> for &'source ReferenceError
impl<'source> FromPyObject<'source> for RuntimeError
impl<'source> FromPyObject<'source> for &'source RuntimeError
impl<'source> FromPyObject<'source> for SyntaxError
impl<'source> FromPyObject<'source> for &'source SyntaxError
impl<'source> FromPyObject<'source> for SystemError
impl<'source> FromPyObject<'source> for &'source SystemError
impl<'source> FromPyObject<'source> for SystemExit
impl<'source> FromPyObject<'source> for &'source SystemExit
impl<'source> FromPyObject<'source> for TypeError
impl<'source> FromPyObject<'source> for &'source TypeError
impl<'source> FromPyObject<'source> for ValueError
impl<'source> FromPyObject<'source> for &'source ValueError
impl<'source> FromPyObject<'source> for ZeroDivisionError
impl<'source> FromPyObject<'source> for &'source ZeroDivisionError
impl<'source> FromPyObject<'source> for UnicodeDecodeError
impl<'source> FromPyObject<'source> for &'source UnicodeDecodeError
impl<'source> FromPyObject<'source> for UnicodeEncodeError
impl<'source> FromPyObject<'source> for &'source UnicodeEncodeError
impl<'source> FromPyObject<'source> for UnicodeTranslateError
impl<'source> FromPyObject<'source> for &'source UnicodeTranslateError