abi_stable/library/c_abi_testing/
c_abi_testing_macros.rs

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
macro_rules! check_roundtrip {
    (
        $funcs:ident,
        $initial_int:expr,
        ($($ret_val:ident=$composite:expr),* $(,)*),

        $ret_fn:ident,
        $take_fn:ident
        $(,)*
    ) => {
        #[allow(unused_parens)]
        {
        let res=($funcs.$ret_fn)($initial_int);
        let composite=($($composite),*);

        if res!=composite {
            return Err(make_invalid_cabi_err(composite.clone(),res.clone()));
        }
        let ($($ret_val),*)=res.clone();
        let int=($funcs.$take_fn)($($ret_val),*);
        if int!=$initial_int {
            return Err(make_invalid_cabi_err(
                (composite.clone(),$initial_int),
                (res.clone(),int),
            ));
        }
    }}
}

macro_rules! anon_struct {
    (
        $($fname:ident : $fval:expr),*
        $(,)*
    ) => {{
        #[allow(non_camel_case_types)]
        struct Anonymous<$($fname),*>{
            $($fname:$fname,)*
        }
        Anonymous{
            $($fname:$fval,)*
        }
    }};
}