Skip to main content

Crate these_macros_should_be_illegal

Crate these_macros_should_be_illegal 

Source
Expand description

Experimental procedural macros for compact local DSLs, recursive token rewriting, and transformations of macro structure.

The main entry points are enum_fn for per-variant methods, discriminated_str for reversible string discriminants, strutuct for nested algebraic declarations, and expand for applying recursive syntax extensions to an out-of-line module. Every macro is independent; import only the syntax used by the caller.


#[enum_fn(code: usize)]
enum Status {
    Ready = 200,
    Missing,
}

assert_eq!(Status::Ready.code(), Some(200));
assert_eq!(Status::Missing.code(), None);

The crate repository contains the complete book and runnable examples.

Macros§

emmun
Declares a family of nested types in place and hoists them into ordinary items.
expand
Loads an out-of-line module and injects function-like macros around its body.
literally_literal_string
Rewrites literal strings in exactly the supplied token stream.
make_fn
Creates a local value and a same-name macro providing function-like calls.
perm
Permutes comma-separated token trees using standard cycle notation.
qf
Qualifies common unqualified standard-library types inside one Rust type.
reflect
Reflects two macro invocation objects around an opaque token-stream body.
shared_match_arms
Clones a shared match-arm RHS for alternatives separated by ||.
stringify_as
Spells one name in a conventional case, or one type canonically, as a string literal.
strutuct
Declares a family of nested types in place and hoists them into ordinary items.

Attribute Macros§

callable
Gives one trait method a structural alias that make_fn! calls through.
complete_ops
Adds the operators that follow from the ones a type already implements.
discriminated_str
Assigns every enum variant one unique string literal.
enum_fn
Generates an enum method from per-variant expressions written beside the variants.
excluded_macros
Prevents transformations from descending into the listed macro invocations.
forward_attributes
Moves the outer attributes of an item-position macro invocation into its input.
overload_op
Repeats an operator implemented for references across its owned forms.