FFORGE//RS
← Roadmap

rust / LEVEL 4

The macro that only worked inside its own crate

EST.40 MIN
01

THEORY / RETRIEVAL

What to restore

  • Use $crate for items owned by the macro-defining crate
  • Choose expr and ident fragments instead of accepting arbitrary token trees
  • Preserve caller expressions, evaluation order and trailing-comma ergonomics

Exported macros expand in someone else's scope

Most item paths written inside a declarative macro are resolved at the invocation site. A helper type that happens to be imported in the defining crate may be absent or shadowed downstream. The special `$crate` metavariable names the crate that defined the macro, even when the consumer renamed that dependency.

Fragment kinds are part of the public syntax

Capture values as `expr` and field names as `ident` when those are the constructs the macro accepts. Precise fragments produce useful compiler diagnostics and preserve parsed Rust syntax. Repetition can support zero or more fields and one optional trailing comma without parsing an unstructured token stream yourself.

CHECKPOINT

Which two choices make an exported macro a reliable cross-crate API?

Select every applicable option. Credit requires an exact set match.

ISOLATED RUST 1.96
src/lib.rsEDIT

02 / DEBUGGING

Find and fix the defect

Repair the exported `event!` macro so a downstream crate can use it after importing only the macro. Keep the invocation syntax, zero-field and trailing-comma support, field order, and exactly-once evaluation. Do not move parsing to runtime.

Initializing editor…
CLOUD SANDBOXnetwork off · 256 MB · 12 s
1 / 64 KB
OUTPUT
Runner is waiting for a submission.