0

I want to document the functions of my python library. I coded it using Rust and the cpython crate. An example of a function follows:

Rust function signature: async fn get_problem(num: u16) -> Result<Problem, ExitFailure> { ... } Rust function wrapper to be able to add function to python module:

fn get_problem_py(_: Python<'_>, num: u16) -> PyResult<Problem> {
    let rt = tokio::runtime::Runtime::new().unwrap();
    let contents = rt.block_on(get_problem(num)).unwrap();

    Ok(contents)
}

py_module_initializer macro:

py_module_initializer!(u_interface, |py, m| {

    ...
    m.add(py, "get_problem", py_fn!(py, get_problem_py(num: u16)))?;
    ...

    Ok(())
});

How can I document this function? Say for example I want the documentation to be "do something"

  • Consider the audience of the documentation. A Python end-use will not care that `get_problem` is implemented in Rust. A developer working on the library may or may not care about the Python interface, only the internal workings of the Rust function. – chepner Apr 02 '23 at 13:06

0 Answers0