Expand description
§metamatch!
A zero dependency proc-macro for practical metaprogramming.
Macro expressions using familiar Rust syntax, evaluated by a tiny interpreter.
§Supported Rust Syntax:
let
statements and pattern matching.loop
,while
,while let
, andfor
loops, includingcontinue
andbreak
if
andelse
blocks- Functions (
fn
) and lambdas (|..|
) - Arrays (
[1,2,3]
) - Ranges (
0..=10
) - All expression operators like
+
or<<
.
§Not supported:
struct
,enum
,type
,trait
, generics, …
§Builtin functions:
lowercase(str) -> str
uppercase(str) -> str
capitalize(str) -> str
enumerate([T]) -> [(int, T)]
zip([A], [B], ..) -> [(A, B, ..)]
map([T], Fn(T) -> U) -> [U]
chars(str) -> [char]
bytes(str) -> [int]
ident(str) -> token
str(any) -> str
len([T]) -> int
String functions also work on tokens.
All functions support UFCS, so [1,2,3].len() == len([1,2,3])
§Special Purpose Macros:
quote! {..} -> [token]
: nested version ofquote!
.raw! {..} -> [token]
: raw Rust, no template tags or expanded meta variables
Just like Rust macros, you can use any of {}
, []
, and ()
interchangably for the macro invocations.
Attribute Macros§
- replicate
- Generate repetitive syntax like trait impls without giving up on
rustfmt
or rust-analyzer.