Summary
Enabling only the redis feature does not compile. The backend re-exports in
backend/mod.rs are correctly gated behind #[cfg(feature = ...)], but
quickstart.rs imports PostgresBackend unconditionally, so the crate fails
with E0432 when the postgres feature is off.
Reproduction
# any Cargo.toml
azums = { version = "1.0", default-features = false, features = ["redis"] }
$ cargo check
error[E0432]: unresolved import `crate::backend::PostgresBackend`
--> src/quickstart.rs:2:5
|
2 | backend::PostgresBackend,
| ^^^^^^^^^^^^^^^^^^^^^^^^ no `PostgresBackend` in `backend`
Workaround: enable postgres alongside redis
(features = ["postgres", "redis"]). Runtime is unaffected — quickstart()
dispatches on the redis:// scheme and returns before the Postgres fallback
path — but the Postgres code is then compiled for nothing.
Root cause (azums 1.0.1)
The Postgres coupling goes deeper than the one import:
1. crates/azums/src/quickstart.rs:2 — use crate::{backend::PostgresBackend, ...}
is not cfg-gated (only usage: line 1059).
2. crates/azums/src/quickstart.rs:984-1065 — the Postgres candidate fallback
(env DATABASE_URL/TEST_DATABASE_URL + hardcoded defaults list) compiles
unconditionally and uses sqlx::postgres::PgPoolOptions.
3. crates/azums/src/jobs/mod.rs — the whole jobs::* repo layer
(repo, attempts, metrics, maintenance, policies, policy_decisions,
ingest_decisions, stream_repo, enqueue_guard) is compiled
unconditionally and every file starts with use sqlx::PgPool.
4. crates/azums/src/lib.rs:120-127 — re-exports those PG repo types
unconditionally.
5. crates/azums/Cargo.toml — the sqlx dependency hardcodes the postgres
and sqlite features, so they are not tied to the crate's own features.
Same pattern in crates/azums-core/Cargo.toml (optional sqlx dep).
Suggested fix
- Split the import and gate it:
#[cfg(feature = "postgres")] use crate::backend::PostgresBackend;
- Wrap the fallback block in #[cfg(feature = "postgres")] { ... } and add a
#[cfg(not(feature = "postgres"))] arm returning a clear error such as
"URL did not match any enabled backend (features: ...)".
- Gate jobs::* (and the db module if PG-only) behind #[cfg(feature = "postgres")],
along with the lib.rs re-exports.
- Make the sqlx features conditional so disabling postgres/sqlite actually
slims the dependency tree:
postgres = ["sqlx/postgres"], sqlite = ["sqlx/sqlite"], with the base
sqlx dep keeping only runtime-tokio-rustls, uuid, chrono, json.
Happy to send a PR if the approach sounds right.
## PR draft
```markdown
Title: Fix feature gating: compile with only one backend feature enabled
## What
Makes each backend feature independently compilable. Before this change,
`default-features = false, features = ["redis"]` (or `["sqlite"]`) fails with
`error[E0432]: unresolved import crate::backend::PostgresBackend`.
## Why
`backend/mod.rs` gates its re-exports per feature, but the rest of the crate
references Postgres types unconditionally:
- `quickstart.rs:2` imports `PostgresBackend` unconditionally (single use at
the `new_with_url` call in the fallback path).
- The Postgres fallback block (`DATABASE_URL`/`TEST_DATABASE_URL` candidates +
hardcoded defaults) at `quickstart.rs:984-1065` is not gated.
- `jobs::*` modules and their `lib.rs` re-exports are compiled unconditionally
and depend on `sqlx::PgPool`.
- The `sqlx` dependency hardcodes `postgres` + `sqlite`, so crate features
never control which sqlx backends are built.
## Changes
- `quickstart.rs`: split out `#[cfg(feature = "postgres")] use
crate::backend::PostgresBackend;`; wrap the Postgres fallback in
`#[cfg(feature = "postgres")]`; without the feature, `quickstart()` returns
an error naming the URL and the enabled features instead of attempting a
Postgres connection.
- `jobs/mod.rs` / `lib.rs`: gate the PG repo layer and its re-exports behind
`#[cfg(feature = "postgres")]`.
- `Cargo.toml` (azums + azums-core): move `postgres`/`sqlite` onto the
corresponding crate features (`postgres = ["sqlx/postgres"]`,
`sqlite = ["sqlx/sqlite"]`); base dep keeps only the driver-agnostic
features.
- Fallback `#[cfg]` arms preserve behavior for default builds; existing tests
run under default features unchanged.
## Testing
- `cargo check -p azums --no-default-features --features redis` (and `sqlite`,
and `postgres` alone) — all compile.
- `cargo test --workspace` (default features) — unchanged.
- `cargo check -p azums --no-default-features` now fails with a clear
"no backend selected" compile error instead of E0432.
Both ready to paste. Want me to build the actual patch in the local azums-1.0.1 tree and verify it compiles first —
turns the PR's Testing section from planned into verified.
Summary
Enabling only the
redisfeature does not compile. The backend re-exports inbackend/mod.rsare correctly gated behind#[cfg(feature = ...)], butquickstart.rsimportsPostgresBackendunconditionally, so the crate failswith E0432 when the
postgresfeature is off.Reproduction