#zip #function #called #traits #compile-time #allowing #combined

nightly fn_zip

Provides a zip trait for functions, allowing two functions to be combined at compile-time before being called

3 releases

0.1.2 Nov 23, 2023
0.1.1 Jul 4, 2023
0.1.0 Jul 4, 2023

#2956 in Rust patterns

Download history 45/week @ 2023-12-14 191/week @ 2023-12-21 309/week @ 2023-12-28 171/week @ 2024-01-04 77/week @ 2024-01-11 10/week @ 2024-01-18 1/week @ 2024-02-08 20/week @ 2024-02-15 43/week @ 2024-02-22 15/week @ 2024-02-29 16/week @ 2024-03-07 19/week @ 2024-03-14 19/week @ 2024-03-21 22/week @ 2024-03-28

77 downloads per month
Used in 4 crates (2 directly)

MIT license

18KB
382 lines

Combines two functions into one where the arguments are conjoined and the return-values are given in a tuple pair.

Example

use fn_zip::FnZip;

fn a(x: f32) -> f64
{
    (x as f64).sqrt()
}
fn b(x: u8) -> u8
{
    x + 1
}
let ab = a.fn_zip(b); // (f32, u8) -> (f64, u8)

let (x_a, x_b) = (4.0, 23);

let (y_a, y_b) = ab(x_a, x_b);

assert_eq!(y_a, a(x_a));
assert_eq!(y_b, b(x_b));

Dependencies

~1.5MB
~35K SLoC