macros

Macro macros 

Source
macro_rules! macros {
    () => { ... };
    (function -> $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (function -> $func:ident , $($tail:tt)*) => { ... };
    (function -> @$path:literal :: $func:ident , $($tail:tt)*) => { ... };
    (function($name:ident) -> $func:ident , $($tail:tt)*) => { ... };
    (function($name:ident) -> $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (function($name:ident) -> @$path:literal :: $func:ident , $($tail:tt)*) => { ... };
    (function($name:ident) -> use $func:ident , $($tail:tt)*) => { ... };
    (function($name:ident) -> use $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (function($name:ident) -> mod $func:ident , $($tail:tt)*) => { ... };
    (function($name:ident) -> mod $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (function($name:ident) -> $path:literal :: $func:ident , $($tail:tt)*) => { ... };
    (attribute -> $func:ident , $($tail:tt)*) => { ... };
    (attribute -> $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (attribute -> @$path:literal :: $func:ident , $($tail:tt)*) => { ... };
    (attribute($name:ident) -> $func:ident , $($tail:tt)*) => { ... };
    (attribute($name:ident) -> $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (attribute($name:ident) -> @$path:literal :: $func:ident , $($tail:tt)*) => { ... };
    (attribute($name:ident) -> use $func:ident , $($tail:tt)*) => { ... };
    (attribute($name:ident) -> use $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (attribute($name:ident) -> mod $func:ident , $($tail:tt)*) => { ... };
    (attribute($name:ident) -> mod $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident, attributes($($attr:ident),*)) -> $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident, attributes($($attr:ident),*)) -> $module:ident :: $func:ident) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> use $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> mod $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident) -> $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident) -> $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident) -> @$path:literal :: $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident) -> use $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident) -> use $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident) -> mod $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident) -> mod $module:ident :: $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> @$path:literal :: $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> use $func:ident , $($tail:tt)*) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> mod $func:ident , $($tail:tt)*) => { ... };
    (function -> $func:ident) => { ... };
    (function -> $module:ident :: $func:ident) => { ... };
    (function -> @$path:literal :: $func:ident) => { ... };
    (function($name:ident) -> $func:ident) => { ... };
    (function($name:ident) -> $module:ident :: $func:ident) => { ... };
    (function($name:ident) -> @$path:literal :: $func:ident) => { ... };
    (function($name:ident) -> use $func:ident) => { ... };
    (function($name:ident) -> use $module:ident :: $func:ident) => { ... };
    (function($name:ident) -> mod $func:ident) => { ... };
    (function($name:ident) -> mod $module:ident :: $func:ident) => { ... };
    (attribute -> $func:ident) => { ... };
    (attribute -> $module:ident :: $func:ident) => { ... };
    (attribute -> @$path:literal :: $func:ident) => { ... };
    (attribute($name:ident) -> $func:ident) => { ... };
    (attribute($name:ident) -> $module:ident :: $func:ident) => { ... };
    (attribute($name:ident) -> @$path:literal :: $func:ident) => { ... };
    (attribute($name:ident) -> use $func:ident) => { ... };
    (attribute($name:ident) -> use $module:ident :: $func:ident) => { ... };
    (attribute($name:ident) -> mod $func:ident) => { ... };
    (attribute($name:ident) -> mod $module:ident :: $func:ident) => { ... };
    (derive($name:ident) -> $func:ident) => { ... };
    (derive($name:ident) -> $module:ident :: $func:ident) => { ... };
    (derive($name:ident) -> @$path:literal :: $func:ident) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> $func:ident) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> $module:ident :: $func:ident) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> @$path:literal :: $func:ident) => { ... };
    (derive($name:ident) -> use $func:ident) => { ... };
    (derive($name:ident) -> use $module:ident :: $func:ident) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> use $func:ident) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> use $module:ident :: $func:ident) => { ... };
    (derive($name:ident) -> mod $func:ident) => { ... };
    (derive($name:ident) -> mod $module:ident :: $func:ident) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> mod $func:ident) => { ... };
    (derive($name:ident, attributes($($attr:ident),+)) -> mod $module:ident :: $func:ident) => { ... };
}
Expand description

Delegates procedural macro declarations to implementation modules.

Note that the implementation modules should not (and can not, which is why this crate exists) include the proc macro attributes (#[proc_macro], #[proc_macro_attribute], or #[proc_macro_derive]).

Uses the specialized macros internally: proc_macro!, attr_macro!, and derive_macro!.

§Supported syntax:

  • function(macro_name) -> impl: Function-like proc macros with custom name
  • function -> impl: Function-like proc macros using function name as macro name
  • attribute(attr_name) -> impl: Attribute proc macros with custom name
  • attribute -> impl: Attribute proc macros using function name as macro name
  • derive(DeriveName) -> impl: Derive proc macros
  • derive(DeriveName, attributes(attr1, attr2)) -> impl: Derive macros with helper attributes

Where impl can be:

  • Direct function: function
  • Module reference with implicit module declaration (default): module::function
  • Module reference with explicit declaration: mod module::function
  • Module reference without declaration (already imported): use module::function
  • Nested modules: a::b::c::function
  • Literal path: "path/to/file.rs"::function
  • Crate-relative path: @"path/from/crate/root.rs"::function

§Examples

include_proc_macro::macros!(
    function(foo) -> foo_mod::implement,
    function -> bar_mod::bar, // uses `bar` as the macro name
     
    // Using an already imported module with the `use` keyword
    function(baz) -> use existing_mod::function_impl,
     
    // Explicitly declaring a module with the `mod` keyword
    function(fizz) -> mod explicit_mod::function_impl,
     
    function(buzz) -> "src/impls/hello.rs"::hello,
    // impl in custom crate path, uses 'world' as the macro name
    function -> @"custom_src/impls/world.rs"::world,  
     
    attribute(my_attr) -> attrs::process,
    attribute(use_attr) -> use imported_attr_mod::process,
    attribute -> attrs::custom,  // uses 'custom' as the macro name
     
    derive(MyDerive) -> derives::generate,
    derive(ImportedDerive) -> use imported_derive_mod::generate,
    derive(NodeTypeChecks, attributes(node_category))
        -> derive_impl_with_attrs::impl_with_attributes // derive with helper attributes
);