Skip to content

feat(cargo): split entity-attribute generators into opt-out features#132

Merged
RAprogramm merged 2 commits into
mainfrom
131
May 11, 2026
Merged

feat(cargo): split entity-attribute generators into opt-out features#132
RAprogramm merged 2 commits into
mainfrom
131

Conversation

@RAprogramm
Copy link
Copy Markdown
Owner

Closes #131

Summary

Every `#[entity(...)]` attribute group now sits behind a Cargo feature flag. All new features ship default-on, so existing builds compile unchanged. Users who want lean builds opt out with `default-features = false` and pick what they need.

New features (default-on)

Feature Gates
`events` `{Entity}Event` enum, lifecycle event variants
`commands` Command structs + dispatcher (`#[entity(commands)]`, `#[command(...)]`)
`hooks` `{Entity}Hooks` trait (manual wiring; #127 tracks auto-invocation)
`transactions` `{Entity}TransactionRepo` adapter + the deprecated `with_*` builders
`aggregate_root` `New{Entity}` constructor + transactional `save()`
`migrations` Compile-time `MIGRATION_UP` / `MIGRATION_DOWN` constants
`projections` Projection structs + `find_by_id_` methods

Plumbing

  • `entity-derive` facade activates each sibling in `entity-derive-impl`. The dep now declares `default-features = false` so transitive defaults don't leak past explicit user selection.
  • Every gated submodule and its `generate(&entity)` call in `entity-derive-impl/src/entity.rs` is wrapped in `#[cfg(feature = "")]`.
  • New helper `guard_disabled_attribute()` emits a `compile_error!` if the entity attribute is used but the feature is disabled — clearer than a missing-method puzzle at the call site.
  • `streams` gains an implicit dependency on `events` (the NOTIFY payload is an event variant).
  • Crate-level `#![cfg_attr(any(not(feature = "migrations"), not(feature = "projections")), allow(dead_code, unused_imports))]` keeps minimal builds warning-clean without micro-managing each parser helper.

README

The feature matrix is rewritten with a Default column, the new features documented, an example for `default-features = false`, and a note about the `compile_error!` guard.

Version bump

Crate Old New
entity-derive-impl 0.6.2 0.6.3
entity-derive 0.8.3 0.8.4

`entity-core` is unchanged.

Test plan

  • `cargo check --all-features` — clean.
  • `cargo check -p entity-derive --no-default-features --features postgres` — clean, no warnings.
  • `cargo check` with each feature individually on top of `postgres` (`events`, `commands`, `hooks`, `transactions`, `aggregate_root`, `migrations`, `projections`) — clean.
  • `cargo test --all-features` — 544 + 9 + 45 + 2 + trybuild pass.
  • `cargo clippy --all-targets --all-features -- -D warnings` — clean.
  • `cargo +nightly fmt --all -- --check` — clean.
  • CI + Codecov green before merge.

Backward compatibility

All new features are default-on. No source change required for existing users. Anyone setting `default-features = false` and forgetting a feature gets a precise `compile_error!` at the offending attribute.

…ures

Every entity-attribute group now lives behind its own Cargo feature so
users can shrink their build by switching off generators they don't need.
All new features ship default-on, so existing projects compile unchanged.

New features (default-on, non-breaking):

- events       — `{Entity}Event` enum, lifecycle event variants
- commands     — command structs, dispatcher trait (`#[entity(commands)]`,
                 `#[command(...)]`)
- hooks        — `{Entity}Hooks` trait (manual wiring; #127 tracks
                 auto-invocation)
- transactions — `{Entity}TransactionRepo` adapter + deprecated `with_*`
                 builders (`#[entity(transactions)]`)
- aggregate_root — `New{Entity}` constructor and transactional `save()`
                   (`#[entity(aggregate_root)]`)
- migrations   — compile-time `MIGRATION_UP`/`MIGRATION_DOWN` constants
                 (`#[entity(migrations)]`)
- projections  — projection structs + `find_by_id_<projection>` methods
                 (`#[projection(...)]`)

Plumbing:

- Each feature in `entity-derive` activates its sibling in
  `entity-derive-impl`. The facade now declares
  `entity-derive-impl = { … default-features = false }` so transitive
  default-on doesn't leak past the user's explicit selection.
- In `entity-derive-impl/src/entity.rs`, every gated submodule and its
  `generate(&entity)` call sits under `#[cfg(feature = "<name>")]`.
- New helper `guard_disabled_attribute()` emits a friendly
  `compile_error!` if the entity attribute is present but the feature is
  off — much clearer than a missing-method puzzle at the call site.
- `streams` now depends on `events` (the NOTIFY payload is an event
  variant; `streams` without `events` would not link).
- Crate-level `#![cfg_attr(any(not(feature = "migrations"), not(feature
  = "projections")), allow(dead_code, unused_imports))]` keeps minimal
  builds warning-free without touching individual parser helpers.

README feature matrix rewritten with a Default column and a "If you use
an entity attribute whose feature is disabled, the macro tells you so"
note plus a `default-features = false` example.

Bump:

- entity-derive-impl: 0.6.2 -> 0.6.3
- entity-derive:      0.8.3 -> 0.8.4

`entity-core` is unchanged.

Closes #131
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@RAprogramm RAprogramm merged commit 937ddf0 into main May 11, 2026
17 checks passed
@RAprogramm RAprogramm deleted the 131 branch May 11, 2026 10:39
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.

feat(cargo): split entity-attribute generators into opt-out features

1 participant