Skip to content

Latest commit

 

History

History
84 lines (55 loc) · 3.58 KB

File metadata and controls

84 lines (55 loc) · 3.58 KB

Architecture

This document explains how the bevy_auto_plugin ecosystem is structured and how macro expansion flows through the crates.

High-Level Flow

  1. User-facing macros are re-exported from bevy_auto_plugin (in src/lib.rs under the prelude).
  2. When a user applies:

Attribute Types

auto_* attributes fall into two categories:

Actions

Each action attribute is modeled as: ItemAttribute<Composed<T, P, G>, R>

Where:

Generic Meaning
T The darling parameter struct for the attribute
P Plugin context: WithPlugin
G Generics handling: WithZeroGenerics, WithZeroOrSingleGenerics, or WithZeroOrManyGenerics
R Resolver restricting usage: AllowAny, AllowFn, or AllowStructOrEnum

notes:

  • Composed can probably be merged into ItemAttribute but it's currently left open if we decide to add macros that aren't attached to the usual items (unlikely).

Actions can implement traits for one or both of the following wrapper types:

  • Responsible for serializing a parsed parameter struct back into attribute tokens (useful for rewrite expansions).

Rewrites

  • Expand into one or more other attributes.
  • Only modify the item’s attributes, not the item body.
  • Uses wrapper type AttrExpansionEmitter<T>

Supporting Infrastructure

Custom Parsing

Located in:
bevy_auto_plugin_shared/src/syntax/ast
Includes custom AST fragments, parsing helpers, and type definitions used across attributes.

Codegen Tokens

All hygienic Bevy paths are centralized in:
bevy_auto_plugin_shared/src/codegen/tokens.rs

Token Preservation

Macro expansions are designed to preserve input tokens on errors.
This ensures IDEs (like rust-analyzer) maintain valid syntax trees and prevent code “going red” on partially-written macro usage.