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:
letstatements and pattern matching.loop,while,while let, andforloops, includingcontinueandbreakifandelseblocks- 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) -> struppercase(str) -> strcapitalize(str) -> strenumerate([T]) -> [(int, T)]zip([A], [B], ..) -> [(A, B, ..)]map([T], Fn(T) -> U) -> [U]chars(str) -> [char]bytes(str) -> [int]ident(str) -> tokenstr(any) -> strlen([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
rustfmtor rust-analyzer.