macro_rules! macro_fallback {
    ($maybe:path, $fallback:path, $($tokens:tt)*) => { ... };
}
Expand description

Call a macro with the given arguments. If the first path does not contain a macro, use the macro at the second path instead.

§Limitations

  • The first path must be valid for some kind of object (i.e. a type, value, or macro).
  • The first path must have a path qualifier (start with ::, crate, self, or super). Otherwise, name resolution will fail.
    (“cannot determine resolution for the macro __macro_fallback import resolution is stuck, try simplifying macro imports”)
  • The macro is expanded within a block, so any items generated will not have a canonical name. Generating impls is the primary use case.

§Example

macro_rules! AMacro {
    ($($tokens:tt)*) => { $($tokens)* };
}
use AMacro as AMacro;

let mut a = false;
macro_fallback!(self::AMacro, telety::noop, a = true;);
assert!(a);

struct NotAMacro;
macro_fallback!(self::NotAMacro, telety::noop, unreachable!());