likejs/
function.rs

1pub mod function{
2    /**
3     * JavaScript arrow function implementation
4     * ```
5     * let f = likejs::arrow!(() => {"Hello, World!".to_string()});
6     * ```
7     * or
8     * ```
9     * let f = likejs::arrow!(() => "Hello, World!".to_string());
10     * ```
11     */
12    #[macro_export]
13    macro_rules! arrow {
14        (($($vars:ident),*) => $stat:block) => {
15            |$($vars),*| {$stat}
16        };
17        (($($vars:ident),*) => $oneline:expr) => {
18            |$($vars),*| {$oneline}
19        };
20    }
21    /**
22     * JavaScript function implementation
23     * ```
24     * likejs::normal_function!(function add(a, b){
25     *     a+b
26     * });
27     * let int = add(12,13);
28     * ```
29     */
30    #[macro_export]
31    macro_rules! normal_function {
32        (function $name:ident($($vars:ident),*) $stat:block) => {
33            let $name = |$($vars: _),*| {$stat};
34        }
35    }
36}