py_buildargs

Function py_buildargs 

Source
pub fn py_buildargs<'a, 'py, T>(
    py: RUMPython<'py>,
    args: &Vec<T>,
) -> RUMResult<RUMPyList>
where T: FromPyObject<'a, 'py> + IntoPyObject<'py> + Debug + Clone,
Expand description

Convert a vector of T to a Python List of T.

ยงExample

    use compact_str::format_compact;
    use pyo3::Python;
    use crate::rumtk_core::scripting::python_utils::{py_buildargs, py_extract_string_vector, py_list_to_tuple};

    let expect: Vec<&str> = vec!["a", "1", "2"];

    Python::attach( |py| {
            let py_args = py_buildargs(py, &expect).unwrap();
            let py_obj = py_list_to_tuple(py, &py_args).unwrap();
            let result = py_extract_string_vector(&py_obj).unwrap();
            assert_eq!(&result, &expect, "{}", format_compact!("Python list does not match the input list!\nGot: {:?}\nExpected: {:?}", &result, &expect));
        }
    )