ConfigProfile

Derive Macro ConfigProfile 

#[derive(ConfigProfile)]
{
    // Attributes available to this derive:
    #[px]
}
Expand description

A macro to derive an implementation of the ConfigProfile trait.

use pavex::config::ConfigProfile;

#[derive(ConfigProfile)]
pub enum Profile {
    Development, // "development"
    Production,  // "production"
}

§Usage

By default, each variant is converted to a snake_case string representation:

use pavex::config::ConfigProfile;
use std::str::FromStr;

#[derive(ConfigProfile)]
pub enum Profile {
    LocalDevelopment, // "local_development"
    Production,  // "production"
}

let p = Profile::from_str("local_development").unwrap();
assert_eq!(p.as_ref(), "local_development");

§Custom Profile Names

You can override the default representation using #[px(profile = "...")]:

use pavex::config::ConfigProfile;
use std::str::FromStr;

#[derive(ConfigProfile)]
pub enum Profile {
    #[px(profile = "dev")]
    Development,
    #[px(profile = "prod")]
    Production,
}

let p = Profile::from_str("dev")?;
assert_eq!(p.as_ref(), "dev");

§Limitations

The macro only works on enums with unit variants. Enums with fields, structs, or unions are not supported and will result in a compile-time error.

If you need more flexibility, consider implementing ConfigProfile manually.