Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Feature Flags

The graphile_worker crate uses feature flags to select the async runtime, TLS implementation, PostgreSQL driver, and optional OpenTelemetry compatibility version.

Default features enable the most common setup:

[dependencies]
graphile_worker = "0.13"

This is equivalent to enabling:

[dependencies]
graphile_worker = {
  version = "0.13",
  features = ["runtime-tokio", "tls-rustls", "driver-sqlx"],
}

Defaults

The default feature set is:

  • runtime-tokio
  • tls-rustls
  • driver-sqlx

Use default-features = false when you want to choose a different runtime, driver, or TLS backend.

[dependencies]
graphile_worker = {
  version = "0.13",
  default-features = false,
  features = ["runtime-async-std", "tls-rustls", "driver-sqlx"],
}

Runtime Features

Runtime features select the async runtime used by the root crate and its internal crates.

FeaturePurpose
runtime-tokioEnables Tokio runtime support. This is enabled by default.
runtime-async-stdEnables async-std runtime support.

The driver-tokio-postgres feature also enables runtime-tokio, so that driver is a Tokio-only combination in the root crate feature graph.

TLS Features

TLS features select the TLS implementation forwarded to database-related crates and, when SQLx is enabled, to SQLx.

FeaturePurpose
tls-rustlsEnables rustls TLS support. This is enabled by default.
tls-native-tlsEnables native-tls support.

The root feature list does not force exactly one TLS backend. Pick the one you intend to use instead of enabling both accidentally.

Database Driver Features

Driver features select the PostgreSQL access layer used by database-related crates.

FeaturePurpose
driver-sqlxEnables SQLx support and the optional sqlx dependency. This is enabled by default.
driver-tokio-postgresEnables tokio-postgres support and also enables runtime-tokio.

SQLx is the default driver. The tokio-postgres driver is available as an alternative Tokio-based driver.

OpenTelemetry Features

OpenTelemetry support is versioned so downstream applications can choose the compatibility line they use.

FeatureDependencies enabled
opentelemetry_0_30opentelemetry 0.30 and matching tracing-opentelemetry support
opentelemetry_0_31opentelemetry 0.31 and matching tracing-opentelemetry support
opentelemetry_0_32opentelemetry 0.32 and matching tracing-opentelemetry support

These features are not enabled by default. Enable the one that matches the OpenTelemetry version used by the rest of your application.

[dependencies]
graphile_worker = {
  version = "0.13",
  features = ["opentelemetry_0_32"],
}

Common Combinations

Default Tokio, rustls, SQLx

Use the default dependency declaration when you want Tokio, rustls, and SQLx.

[dependencies]
graphile_worker = "0.13"

Tokio, native-tls, SQLx

Disable defaults and select the TLS backend explicitly.

[dependencies]
graphile_worker = {
  version = "0.13",
  default-features = false,
  features = ["runtime-tokio", "tls-native-tls", "driver-sqlx"],
}

async-std, rustls, SQLx

Use the async-std runtime with the SQLx driver.

[dependencies]
graphile_worker = {
  version = "0.13",
  default-features = false,
  features = ["runtime-async-std", "tls-rustls", "driver-sqlx"],
}

Tokio, tokio-postgres

The tokio-postgres driver enables runtime-tokio through the feature graph.

[dependencies]
graphile_worker = {
  version = "0.13",
  default-features = false,
  features = ["driver-tokio-postgres"],
}

If your connection setup needs TLS, also select the TLS feature you intend to use:

[dependencies]
graphile_worker = {
  version = "0.13",
  default-features = false,
  features = ["driver-tokio-postgres", "tls-rustls"],
}

Tokio, SQLx, OpenTelemetry 0.32

OpenTelemetry features can be added to the default feature set.

[dependencies]
graphile_worker = {
  version = "0.13",
  features = ["opentelemetry_0_32"],
}

Feature Matrix Used by Local Checks

The repository's runtime matrix checks the following combinations:

just test-docker-all-matrices

That command covers:

RuntimeDriverTLS
runtime-tokiodriver-sqlxtls-rustls
runtime-async-stddriver-sqlxtls-rustls
runtime-tokiodriver-tokio-postgresnot selected by the test recipe

The test-runtime recipe rejects driver-tokio-postgres with runtime-async-std, matching the feature relationship where driver-tokio-postgres enables Tokio.

Cautions

Disable defaults when replacing a default feature. For example, adding tls-native-tls without default-features = false leaves tls-rustls enabled too.

[dependencies]
graphile_worker = {
  version = "0.13",
  default-features = false,
  features = ["runtime-tokio", "tls-native-tls", "driver-sqlx"],
}

Choose one database driver unless you have checked that your application really needs both. The default driver is SQLx, so enabling driver-tokio-postgres without disabling defaults enables both drivers.

[dependencies]
graphile_worker = {
  version = "0.13",
  default-features = false,
  features = ["driver-tokio-postgres"],
}

Use an OpenTelemetry feature only when your dependency graph uses that matching OpenTelemetry line. The root crate exposes separate compatibility features for 0.30, 0.31, and 0.32.

Illustrative Rust examples in this documentation may require additional setup, such as task handlers, worker options, and a database URL. See the quick start for a complete first worker.

// Feature selection happens in Cargo.toml, not in Rust source.
use graphile_worker::WorkerOptions;