Macro rustypy::unpack_pytuple
[−]
[src]
macro_rules! unpack_pytuple { ($t:ident; ($($p:tt,)+) ) => { ... }; ($t:ident; $i:ident; elem: ($($p:tt,)+)) => { ... }; ($t:ident; $i:ident; elem: {PyDict{$u:tt}}) => { ... }; ($t:ident; $i:ident; elem: {PyList{$($u:tt)*}}) => { ... }; ($t:ident; $i:ident; elem: PyBool) => { ... }; ($t:ident; $i:ident; elem: PyString) => { ... }; ($t:ident; $i:ident; elem: I64) => { ... }; ($t:ident; $i:ident; elem: I32) => { ... }; ($t:ident; $i:ident; elem: I16) => { ... }; ($t:ident; $i:ident; elem: I8) => { ... }; ($t:ident; $i:ident; elem: U32) => { ... }; ($t:ident; $i:ident; elem: U16) => { ... }; ($t:ident; $i:ident; elem: U8) => { ... }; ($t:ident; $i:ident; elem: F32) => { ... }; ($t:ident; $i:ident; elem: F64) => { ... }; }
Iterates over a a PyTuple and returns a corresponding Rust tuple.
When destructured all inner data is moved out of the tuple which will retain the structure but will point to PyArg::None variant, so is safe to assume the PyTuple as consumed.
Inner containers (ie. PyList<PyArg(T)>
) are converted to the respective Rust analog
(ie. Vec<T>
) and require valid syntax for their respective unpack macro (ie.
unpack_pytuple!).
Examples
Unpack a PyTuple which contains a two PyDict types with PyString keys
and values of PyList
// tuple from Python: ({"one": [0, 1, 3], "two": [3, 2, 1]}) let mut pytuple = unsafe { PyTuple::from_ptr(pytuple) }; let unpacked = unpack_pytuple!(pytuple; ({PyDict{(PyString, PyList{I32 => i64})}}, {PyDict{(PyString, PyList{I32 => i64})}},));