Closed
Description
It is often confusing trying to figure out how to write a #[pyfunction]
signature that will match the Python signature you want (see #373, for example).
It would be great to have two lookup tables for all native types, one mapping the Python -> Rust, for writing the types of the function parameters, and another mapping Rust -> Python, saying the type of the object you'll get if you return a given type. So the first table would look like this:
Python | Rust |
---|---|
int |
Any integer type (i32 , u32 , usize , etc) |
list |
Vec<T> , &PyList |
tuple |
Vec<T> , &PyTuple |
str |
String , &PyUnicode |
The second one might look like this:
Rust | Python |
---|---|
Vec<T> |
list |
u8 , u16 , etc |
int |
I don't think it needs to be comprehensive, but at least for some of the basic types (and especially showing the preferred way to do things) would be super helpful.