3 releases (1 stable)
1.0.0 | Mar 30, 2023 |
---|---|
0.1.1 | Mar 25, 2023 |
0.1.0 | Mar 24, 2023 |
#1981 in Procedural macros
15KB
167 lines
auto_curry
Procedural macro for currying most functions in Rust.
This procedural macro can be thought of as a complete version of
the unfinished Rust library, cutlass
.
add
Example (/examples/add.rs):
use auto_curry::curry;
#[curry]
fn add(a: i32, b: i32) -> i32 {
a + b
}
fn main() {
assert_eq!(add(1)(2), 3);
println!("{} = {}", add(1)(2), 3);
}
How it expands:
As of version 0.1.0, the add function in the example above expands exactly to:
fn add(a: i32) -> impl Fn(i32) -> i32 {
move |b| { a + b }
}
As far as I am aware, this is the most performant expansion in stable rust.
Capabilities:
- Can handle funtions with a self receiver.
- Can handle functions with generics and GAT's.
- Works on stable.
Known issues:
- waiting on
impl_trait_in_fn_trait_return
(or alternatively,type_alias_impl_trait
) to be able to significantly optimize curried functions.
Dependencies
~2MB
~45K SLoC