Skip to content

docs(hooks): clarify manual-wiring requirement; track auto-invocation in #127#128

Merged
RAprogramm merged 1 commit into
mainfrom
126-hooks-docs-clarify
May 11, 2026
Merged

docs(hooks): clarify manual-wiring requirement; track auto-invocation in #127#128
RAprogramm merged 1 commit into
mainfrom
126-hooks-docs-clarify

Conversation

@RAprogramm
Copy link
Copy Markdown
Owner

Closes #126
Follow-up RFC: #127

Summary

`#[entity(hooks)]` emits the `{Entity}Hooks` trait. The current docs imply that generated CRUD will call the hooks; it doesn't, and orphan rule prevents users from making it call them with a local impl. Honest documentation fix while #127 designs the wrapper-struct architecture.

Changes

  • `hooks.rs` module docs — new "Status" section + rewritten Usage example using a service struct that owns the pool (the only pattern that actually compiles).
  • Generated trait rustdoc — "Invocation is manual" warning visible on hover.
  • `README.md` feature row — soften "Lifecycle Hooks" wording and link RFC: auto-invoke {Entity}Hooks from generated Repository methods #127.
  • `examples/hooks/src/main.rs` — top-of-file banner naming the manual-wiring pattern.

No runtime behavior change.

Out of scope

`#127` tracks the real fix: `{Entity}Repo` wrapper that threads hook calls through every CRUD method. That's a minor-version bump and deserves a separate PR.

Test plan

  • `cargo test --all-features` — full suite passes (no changes to generated code, just docs).
  • `cargo clippy --all-targets --all-features -- -D warnings` — clean.
  • `cargo +nightly fmt --all -- --check` — clean.
  • `RUSTDOCFLAGS="-D warnings" cargo doc --all-features --no-deps` — clean.
  • CI green.

…ation in #127

`#[entity(hooks)]` emits the `{Entity}Hooks` trait but the generated
`impl {Entity}Repository for sqlx::PgPool` never calls it. Users reading
the docs reasonably expect the generator to wire the two together —
they don't, because Rust's orphan rule blocks user crates from writing
`impl …Hooks for PgPool` (both type and trait are foreign).

Until full auto-invocation lands, document the actual contract:

- `crates/entity-derive-impl/src/entity/hooks.rs` module docs grow a
  prominent "Status" block explaining the manual-wiring requirement and
  linking the tracking issue (#127). The usage example is rewritten so
  it no longer suggests `impl UserHooks for MyRepo(PgPool)` (orphan-ruled
  out) — the recommended pattern is a service struct that owns the pool.
- The generated trait's doc comment carries the same "Invocation is
  manual" warning so users hovering on the trait in their IDE see it.
- `README.md` features table softens the "Lifecycle Hooks" bullet to
  reflect the current opt-in / manual-fire contract and links to #127.
- `examples/hooks/src/main.rs` gains a top-of-file banner naming the
  pattern explicitly so readers don't waste time looking for the missing
  auto-wiring.

No runtime behavior change. The follow-up issue #127 holds the design
discussion for the actual fix (a `{Entity}Repo<H>` wrapper struct that
threads hook calls through every CRUD method).

Closes #126
@RAprogramm RAprogramm merged commit 61300c6 into main May 11, 2026
17 checks passed
@RAprogramm RAprogramm deleted the 126-hooks-docs-clarify branch May 11, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(hooks): document manual wiring requirement; plan auto-invocation in follow-up

1 participant