mehcode / config-rs

⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Apache License 2.0
2.43k stars 206 forks source link

Question: Is there a way to embed config files? #408

Closed bryantbiggs closed 1 year ago

bryantbiggs commented 1 year ago

If I am distributing a CLI, the executable currently fails because the config files do not travel with the binary. I don't know if I am missing something obvious but is there a way to embed the configuration files referenced? Something like

use config::{Config, ConfigError, File};
use rust_embed::RustEmbed;

#[derive(RustEmbed)]
#[folder = "assets/"]
struct Asset;

let s = Config::builder().add_source(File::with_name("assets/config.yaml")).build()?;
s.try_deserialize()
matthiasbeyer commented 1 year ago

You're already using rust_embed up there, that already embeds the file in your binary. You just have to use it from there!