# Functional trait
## Description
A simple macro that inspired by java's functional interface.
the macro impls a trait for [Fn], [FnMut] or [FnOnce] when the trait:
- contains one and only one method
- the method has a receiver, and the receiver is `&self`, `&mut self` or `self`
- has no generic types in the method
- is not unsafe
## Example
```rust
use functional_trait::functional_trait;
#[functional_trait]
trait A {
fn a(&self, i: i32, j: i32) -> i32;
}
#[functional_trait]
trait B {
fn b(&mut self, i: i32, j: i32) -> i32;
}
#[functional_trait]
trait C {
fn c(self, i: i32, j: i32) -> i32;
}
#[functional_trait]
trait D {
fn d<'c>(&self, b: &'c i32) -> &'c i32;
}
#[functional_trait]
trait E<'a, T: 'a + ?Sized, const AA: usize, T1>: Sized + Clone + Send
where
T1: Send + Sync,
T: std::fmt::Display,
{
unsafe fn e<'c>(&'c self, a: &'a T, b: [i32; AA], t1: T1) -> &'a str;
}
let mut i = 0;
a + b + i
};
dbg!(fb.b(1, 2));
let s = String::new();
a + b + i
};
dbg!(fc.c(1, 2));
let fd = {
fn f(a: &i32) -> &i32 {
a
}
f
};
fd.d(&1);