const-anonymous-functions 1.1.0

Simple macro to create const anonymous functions
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/// A macro for creating const anonymous functions.
///
/// The syntax is closure syntax but with a couple of caveats. Namely:
/// - All types must be explicitly annotated, including the return type.
/// - The body must always be surrounded by braces.
///
/// See the [module-level documentation](crate) for more info.
#[macro_export]
macro_rules! caf {
	(|$($arg:tt: $arg_ty:ty),*| $(-> $return_ty:ty)? { $body:expr }) => {
		{
			const fn __anon_caf__($($arg: $arg_ty),*) $(-> $return_ty)? {
				$body
			}
			__anon_caf__
		}
	};
}