File: macros_all_the_way_down.rs

package info (click to toggle)
rust-async-recursion 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 332 kB
  • sloc: makefile: 2
file content (26 lines) | stat: -rw-r--r-- 553 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
use futures_executor::block_on;

macro_rules! recurse {
    ($name:ident, $param:ty) => {
        #[::async_recursion::async_recursion]
        async fn $name<F>(param: $param, f: &F)
        where
            F: Fn($param) + Sync + Send,
        {
            f(param);
        }
    };
}

recurse!(owned, usize);
recurse!(by_ref, &usize);
recurse!(by_ref_mut, &mut usize);

#[test]
fn async_in_macro() {
    block_on(async move {
        owned(5, &|_| ()).await;
        by_ref(&5, &|_| ()).await;
        by_ref_mut(&mut 5, &|_| ()).await;
    });
}