Cargo permits dependency aliases. In v0.9.0 the derive macros can generate paths through that alias, which is useful in workspaces that reserve the canonical crate name:
[dependencies]
config_layer = { package = "ortho_config", version = "0.9.0" }
serde = { version = "1.0", features = ["derive"] }
Name the alias on every type that derives an OrthoConfig macro:
use config_layer::{OrthoConfig, OrthoResult};
use serde::Deserialize;
#[derive(Deserialize, OrthoConfig)]
#[ortho_config(crate = "config_layer", prefix = "ACME_")]
struct Config {
#[ortho_config(default = 8080)]
port: u16,
}
fn main() -> OrthoResult<()> {
let config = Config::load_from_iter(["acme"])?;
assert_eq!(config.port, 8080);
println!("port={}", config.port);
Ok(())
}
The same attribute is supported by SelectedSubcommandMerge. OrthoConfig
re-exports the dependencies used by generated code, so a derive-only consumer
does not need direct figment, uncased, xdg, or format-parser dependencies.