Quality of life macro for generic functions
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
Hello there!
im currently using something like this in my project (please ignore the specifics, i want to share the general idea without ripping it out of the context that sparked the idea):
macro_rules! concrete_ordinal_encoding {
($typename: ident, $pymodule: ident) => {
paste::item! {
#[pyfunction]
fn [< ordinal_encoding_$typename >]<'py>(py: Python<'py>, labels: Vec<$typename>) -> &'py PyArray1<usize> {
ordinal_encoding(labels).into_pyarray(py)
}
$pymodule.add_function(wrap_pyfunction!([< ordinal_encoding_$typename >], $pymodule)?)?;
}
};
}
So, naturally, i wondered: is it a good idea to turn it into some sort of concrete_function!() macro to specialize generic functions to interface with python? on the python side, it could be implemented with an object with __getitem__ or __getattr__ to resolve what specific function to call.
Do you think it is worth a dependency? Do you think this approach smells nice enough to be included in pyo3?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the shown concrete_ordinal_encoding! macro and assess how a concrete_function! macro could specialize generic functions for Python. Consider the proposed Python-side getitem or getattr resolution and whether this belongs in PyO3 or requires a dependency. Done means reaching a clear decision on the API and scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100