fn_ops

Crates.iofn_ops
lib.rsfn_ops
version0.1.0
sourcesrc
created_at2015-12-24 14:43:24.130021
updated_at2015-12-24 14:43:24.130021
descriptionTemporary traits for function operator overloading, pending the stabilization of `Fn`, `FnMut`, and `FnOnce`.
homepagehttps://github.com/bjz/fn_ops
repositoryhttps://github.com/bjz/fn_ops
max_upload_size
id3743
size19,509
Brendan Zabarauskas (brendanzab)

documentation

http://bjz.github.io/fn_ops

README

fn_ops

Build Status Version License Downloads

Documentation

Temporary traits for function operator overloading, pending the stabilization of Fn, FnMut, and FnOnce.

use fn_ops::*;

struct IsMultipleOf(i32);

impl FnOnce<(i32, i32)> for IsMultipleOf {
    type Output = bool;

    fn call_once(self, (x, y): (i32, i32)) -> bool { self.call((x, y)) }
}

impl FnMut<(i32, i32)> for IsMultipleOf {
    fn call_mut(&mut self, (x, y): (i32, i32)) -> bool { self.call((x, y)) }
}

impl Fn<(i32, i32)> for IsMultipleOf {
    fn call(&self, (x, y): (i32, i32)) -> bool {
        x * self.0 == y
    }
}

fn assert_fn<Args, F: Fn<Args, Output = bool>>(args: Args, f: F) {
    assert!(f.call(args))
}

assert_fn((1, 2), IsMultipleOf(2));
assert_fn((1, 2, 3), |x, y, z| x != y && y != z && z != x);
Commit count: 8

cargo fmt