higher_order_closure/
lib.rs

1#![cfg_attr(feature = "better-docs",
2    cfg_attr(all(), doc = include_str!("../README.md")),
3)]
4#![no_std]
5#![forbid(unsafe_code)]
6
7pub use higher_order_closure as hrtb;
8
9/// See [the main docs][crate] for more info.
10#[macro_export]
11macro_rules! higher_order_closure {(
12    $(#![
13        with<
14            $($(
15                $lt:lifetime $(: $super_lt:lifetime)?
16            ),+ $(,)?)?
17            $($(
18                $T:ident $(:
19                    $(
20                        ?$Sized:ident $(+)?
21                    )?
22                    $(
23                        $super:lifetime $(+)?
24                    )?
25                    $(
26                        $Trait:path
27                    )?
28                )?
29            ),+ $(,)?)?
30        >
31        $(where
32            $($wc:tt)*
33        )?
34    ])?
35
36    $( for<$($hr:lifetime),* $(,)?> )?
37    $( move $(@$move:tt)?)?
38    | $($arg_pat:tt : $ArgTy:ty),* $(,)?|
39      -> $Ret:ty
40    $body:block
41) => (
42    ({
43        fn __funnel__<
44            $(
45                $($(
46                    $lt $(: $super_lt)?
47                    ,
48                )+)?
49                $($(
50                    $T
51                    $(:
52                        $(?$Sized +)?
53                        $($super +)?
54                        $($Trait)?
55                    )?
56                    ,
57                )+)?
58            )?
59                __Closure,
60            >
61        (
62            f: __Closure,
63        ) -> __Closure
64        where
65            __Closure : for<$($($hr ,)*)?> $crate::__::FnOnce($($ArgTy),*) -> $Ret,
66            $($($($wc)*)?)?
67        {
68            f
69        }
70
71        __funnel__::<$($($($T ,)+)?)? _>
72    })(
73        $(move $($move)?)? |$($arg_pat),*| $body
74    )
75)}
76
77// macro internals
78#[doc(hidden)] /** Not part of the public API */ pub
79mod __ {
80    pub use ::core::ops::FnOnce;
81}
82
83#[cfg_attr(feature = "ui-tests",
84    cfg_attr(all(), doc = include_str!("compile_fail_tests.md")),
85)]
86mod _compile_fail_tests {}