pub fn py_push_arg<'a, 'py, T>(
py: RUMPython<'py>,
py_args: &mut RUMPyList,
arg: &T,
) -> RUMResult<()>Expand description
Push argument of type T into instance of Python List. We can then use the list to pass
arguments to Python function or method.
ยงExample
use compact_str::format_compact;
use pyo3::Python;
use pyo3::types::{PyListMethods, PyAnyMethods};
use crate::rumtk_core::scripting::python_utils::{py_new_args, py_push_arg, RUMPyArgs, RUMPyList};
use crate::rumtk_core::scripting::python_utils::{py_buildargs, py_extract_string_vector};
Python::attach( |py| {
let example_arg_1 = 1;
let example_arg_2 = "Hello";
let mut py_args: RUMPyList = py_new_args(py);
py_push_arg(py, &mut py_args, &example_arg_1.clone()).unwrap();
py_push_arg(py, &mut py_args, &example_arg_2.clone()).unwrap();
let arg_1: usize = py_args.bind(py).get_item(0).unwrap().extract().unwrap();
assert_eq!(&example_arg_1, &arg_1, "{}", format_compact!("Python list does not match the input list!\nGot: {:?}\nExpected: {:?}", &arg_1, &example_arg_1));
}
)