Skip to content

On types

#[pavex::config] and #[pavex::prebuilt] must be applied to types, rather than functions and methods.

Definitions

You can annotate struct, enum and type alias definitions:

use pavex::config;

#[config(key = "pool")] // (1)!
#[derive(serde::Deserialize, Debug, Clone)]
pub struct PoolConfig {
    pub max_n_connections: u32,
    pub min_n_connections: u32,
}
  1. #[pavex::config] goes on top of the struct definition. It doesn't have to be above other attributes, unless they modify the struct definition.

Re-exports

You may wish to use types defined in another crate as Pavex components. If they've been annotated by the library author, it's just a matter of importing them into your blueprint. But what if they haven't?

You can't add annotations to types defined in third-party crates. However, you can still use them as Pavex components via an annotated re-export:

use pavex::prebuilt;

#[prebuilt] // (1)!
pub use reqwest::Client;
  1. You can't apply #[pavex::prebuilt] where reqwest::Client is defined, since it's in a third-party crate. But you can avoid boilerplate by annotating its re-export.

This is equivalent to annotating the definition of reqwest::Client directly with #[pavex::prebuilt].