[−][src]Trait cpython::FromPyObject
FromPyObject is implemented by various types that can be extracted from a Python object.
Normal usage is through the PyObject::extract
helper method:
let value = 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 Cow<'source, [u8]>
[src]
Allows extracting byte arrays from Python objects.
For Python bytes
, returns a reference to the existing immutable string data.
For other types, converts to an owned Vec<u8>
.
impl<'source> FromPyObject<'source> for bool
[src]
fn extract(py: Python, obj: &'source PyObject) -> PyResult<Self>
[src]
Converts a Python bool
to a rust bool
.
Fails with TypeError
if the input is not a Python bool
.
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]
Loading content...
T: FromPyObject<'a>,
Implementors
impl<'source> FromPyObject<'source> for &'source AssertionError
[src]
impl<'source> FromPyObject<'source> for &'source AttributeError
[src]
impl<'source> FromPyObject<'source> for &'source BaseException
[src]
impl<'source> FromPyObject<'source> for &'source BufferError
[src]
impl<'source> FromPyObject<'source> for &'source EOFError
[src]
impl<'source> FromPyObject<'source> for &'source EnvironmentError
[src]
impl<'source> FromPyObject<'source> for &'source Exception
[src]
impl<'source> FromPyObject<'source> for &'source FloatingPointError
[src]
impl<'source> FromPyObject<'source> for &'source IOError
[src]
impl<'source> FromPyObject<'source> for &'source ImportError
[src]
impl<'source> FromPyObject<'source> for &'source IndexError
[src]
impl<'source> FromPyObject<'source> for &'source KeyError
[src]
impl<'source> FromPyObject<'source> for &'source KeyboardInterrupt
[src]
impl<'source> FromPyObject<'source> for &'source LookupError
[src]
impl<'source> FromPyObject<'source> for &'source MemoryError
[src]
impl<'source> FromPyObject<'source> for &'source NameError
[src]
impl<'source> FromPyObject<'source> for &'source NotImplementedError
[src]
impl<'source> FromPyObject<'source> for &'source OSError
[src]
impl<'source> FromPyObject<'source> for &'source OverflowError
[src]
impl<'source> FromPyObject<'source> for &'source ReferenceError
[src]
impl<'source> FromPyObject<'source> for &'source RuntimeError
[src]
impl<'source> FromPyObject<'source> for &'source SyntaxError
[src]
impl<'source> FromPyObject<'source> for &'source SystemError
[src]
impl<'source> FromPyObject<'source> for &'source SystemExit
[src]
impl<'source> FromPyObject<'source> for &'source TypeError
[src]
impl<'source> FromPyObject<'source> for &'source UnicodeDecodeError
[src]
impl<'source> FromPyObject<'source> for &'source UnicodeEncodeError
[src]
impl<'source> FromPyObject<'source> for &'source UnicodeTranslateError
[src]
impl<'source> FromPyObject<'source> for &'source ValueError
[src]
impl<'source> FromPyObject<'source> for &'source ZeroDivisionError
[src]
impl<'source> FromPyObject<'source> for &'source PyBool
[src]
impl<'source> FromPyObject<'source> for &'source PyBytes
[src]
impl<'source> FromPyObject<'source> for &'source PyCapsule
[src]
impl<'source> FromPyObject<'source> for &'source PyDict
[src]
impl<'source> FromPyObject<'source> for &'source PyFloat
[src]
impl<'source> FromPyObject<'source> for &'source PyLong
[src]
impl<'source> FromPyObject<'source> for &'source PyList
[src]
impl<'source> FromPyObject<'source> for &'source PyModule
[src]
impl<'source> FromPyObject<'source> for &'source PyObject
[src]
impl<'source> FromPyObject<'source> for &'source PySequence
[src]
impl<'source> FromPyObject<'source> for &'source PySet
[src]
impl<'source> FromPyObject<'source> for &'source PyString
[src]
impl<'source> FromPyObject<'source> for &'source PyTuple
[src]
impl<'source> FromPyObject<'source> for &'source PyType
[src]
impl<'source> FromPyObject<'source> for AssertionError
[src]
impl<'source> FromPyObject<'source> for AttributeError
[src]
impl<'source> FromPyObject<'source> for BaseException
[src]
impl<'source> FromPyObject<'source> for BufferError
[src]
impl<'source> FromPyObject<'source> for EOFError
[src]
impl<'source> FromPyObject<'source> for EnvironmentError
[src]
impl<'source> FromPyObject<'source> for Exception
[src]
impl<'source> FromPyObject<'source> for FloatingPointError
[src]
impl<'source> FromPyObject<'source> for IOError
[src]
impl<'source> FromPyObject<'source> for ImportError
[src]
impl<'source> FromPyObject<'source> for IndexError
[src]
impl<'source> FromPyObject<'source> for KeyError
[src]
impl<'source> FromPyObject<'source> for KeyboardInterrupt
[src]
impl<'source> FromPyObject<'source> for LookupError
[src]
impl<'source> FromPyObject<'source> for MemoryError
[src]
impl<'source> FromPyObject<'source> for NameError
[src]
impl<'source> FromPyObject<'source> for NotImplementedError
[src]
impl<'source> FromPyObject<'source> for OSError
[src]
impl<'source> FromPyObject<'source> for OverflowError
[src]
impl<'source> FromPyObject<'source> for ReferenceError
[src]
impl<'source> FromPyObject<'source> for RuntimeError
[src]
impl<'source> FromPyObject<'source> for SyntaxError
[src]
impl<'source> FromPyObject<'source> for SystemError
[src]
impl<'source> FromPyObject<'source> for SystemExit
[src]
impl<'source> FromPyObject<'source> for TypeError
[src]
impl<'source> FromPyObject<'source> for UnicodeDecodeError
[src]
impl<'source> FromPyObject<'source> for UnicodeEncodeError
[src]
impl<'source> FromPyObject<'source> for UnicodeTranslateError
[src]
impl<'source> FromPyObject<'source> for ValueError
[src]
impl<'source> FromPyObject<'source> for ZeroDivisionError
[src]
impl<'source> FromPyObject<'source> for NoArgs
[src]
fn extract(py: Python, obj: &'source PyObject) -> PyResult<Self>
[src]
Returns Ok(NoArgs)
if the input is an empty Python tuple.
Otherwise, returns an error.