https://github.com/brendanzab/fn_ops
Traits for function operator overloading
https://github.com/brendanzab/fn_ops
Last synced: 5 months ago
JSON representation
Traits for function operator overloading
- Host: GitHub
- URL: https://github.com/brendanzab/fn_ops
- Owner: brendanzab
- License: apache-2.0
- Created: 2015-12-24T13:47:40.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-11T03:20:28.000Z (about 10 years ago)
- Last Synced: 2025-08-18T03:40:08.267Z (5 months ago)
- Language: Rust
- Homepage: http://bjz.github.io/fn_ops
- Size: 523 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
README
# fn_ops
[](https://travis-ci.org/bjz/fn_ops)
[](https://crates.io/crates/fn_ops)
[](https://github.com/bjz/fn_ops/blob/master/LICENSE)
[](https://crates.io/crates/fn_ops)
[Documentation](http://bjz.github.io/fn_ops)
Temporary traits for function operator overloading, pending the stabilization of
`Fn`, `FnMut`, and `FnOnce`.
```rust
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: 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);
```