fn_zip
Provides a zip trait for functions, allowing two functions to be combined before being called. This is equivalent to core::future::join!(), but lazy, and works for non-async functions.
The resulting function takes the arguments of both functions and return a tuple.
Example
use *;
let ab = a.fn_zip; // (f32, u8) -> (f64, u8)
let = ;
let = ab;
assert_eq!;
assert_eq!;
Async
The zipped functions can also implement AsyncFnOnce, AsyncFnMut and AsyncFn if both functions qualify.
This is an experimental feature, since it just recently (as of writing) got added to the rust core library on rust-nightly, and may be subject to change at any point. Enable it with feature async or experimental.
use *;
use AsyncFn;
async
async
let ab = a.fn_zip;
let = ;
// I don't know of any prettier way to call an async function...
let = ab.async_call.await;
assert_eq!;
assert_eq!;
Independent of this feature, it's still possible to zip two asyncronous functions normally, but their futures will not be joined.
Compile time function zipping
Functions can also be zipped during compile-time.
use *;
// Corce functions into function pointers
const A: fn = a;
const B: fn = b;
// Zip during compile time
const AB: = A.fn_zip_once;
let = ;
let = AB;
assert_eq!;
assert_eq!;
Tuple sizes
By default, this crate operates with function pairs of up to 16 arguments combined, and splits them up in the form of tuples. If you want to use differently sized tuples, use the features 8, 16, 32, 64, 96, 128, 160, 192, 224 or 256 to set the maximum supported tuple size.
The dont_hurt_yourself_by_using_all_features is there to prevent usage of tuples bigger than 8 if cargo is ran with the flag --all-features. Using a tuple size above 16 is highly discouraged as it will make compilation time unbearably long. Compilation time will increase exponentially. You have been warned.