| Crates.io | cutlass |
| lib.rs | cutlass |
| version | 0.1.0 |
| created_at | 2020-05-05 08:38:48.42974+00 |
| updated_at | 2020-05-05 08:38:48.42974+00 |
| description | Macro based library to take the boilerplate out of configuration handling |
| homepage | |
| repository | https://github.com/nerdypepper/cutlass |
| max_upload_size | |
| id | 237658 |
| size | 7,973 |
experimental auto-currying for rust functions
this currently works only on nightly with the
type_alias_impl_trait feature enabled.
#![feature(type_alias_impl_trait)]
#[cutlass::curry]
fn add(x: u32, y: u32, z: u32) -> u32 {
return x + y + z;
}
fn main() {
let plus_3 = add(1)(2);
let v: Vec<u32> = (1..=3).map(plus_3).collect();
assert_eq!(v, vec![4, 5, 6]);
}
the #[curry] proc-macro expands the above add function to
something like this (roughly):
type T0 = u32;
type T1 = impl Fn(u32) -> T0;
type T2 = impl Fn(u32) -> T1;
fn add(x: u32) -> T2 {
return (move |y| move |z| x + y + z);
}
self)type_alias_impl_trait
enabledtest this crate with cargo +nightly test.
to view macro expansions, install cargo-expand and run cargo expand --test <test name>. expand tests/smoke.rs for example:
cargo expand --test smoke