| Crates.io | scuffle-settings |
| lib.rs | scuffle-settings |
| version | 0.1.4 |
| created_at | 2024-11-28 16:48:27.187188+00 |
| updated_at | 2025-05-17 13:36:19.740286+00 |
| description | Tools for managing configuration from environment variables or config files. |
| homepage | |
| repository | https://github.com/scufflecloud/scuffle |
| max_upload_size | |
| id | 1464774 |
| size | 66,042 |
[!WARNING]
This crate is under active development and may not be stable.
A crate designed to provide a simple interface to load and manage settings.
This crate is a wrapper around the config crate and clap crate
to provide a simple interface to load and manage settings.
See the changelog for a full release history.
cli — Enables cli parsing using clapron — Enables the ron formattoml — Enables the toml formatyaml — Enables the yaml formatjson — Enables the json formatjson5 — Enables the json5 formastini — Enables the ini formatall-formats — Enables all formatstemplates — Enables templating support via jinjabootstrap — Enables scuffle-bootstrap supportfull — Enables everythingdocs — Enables changelog and documentation of feature flagsscuffle_bootstrap// Define a config struct like this
// You can use all of the serde attributes to customize the deserialization
#[derive(serde_derive::Deserialize)]
struct MyConfig {
some_setting: String,
#[serde(default)]
some_other_setting: i32,
}
// Implement scuffle_boostrap::ConfigParser for the config struct like this
scuffle_settings::bootstrap!(MyConfig);
/// Our global state
struct Global;
impl scuffle_bootstrap::global::Global for Global {
type Config = MyConfig;
async fn init(config: MyConfig) -> anyhow::Result<Arc<Self>> {
// Here you now have access to the config
Ok(Arc::new(Self))
}
}
scuffle_bootstrap// Define a config struct like this
// You can use all of the serde attributes to customize the deserialization
#[derive(serde_derive::Deserialize)]
struct MyConfig {
some_setting: String,
#[serde(default)]
some_other_setting: i32,
}
// Parsing options
let options = scuffle_settings::Options {
env_prefix: Some("MY_APP"),
..Default::default()
};
// Parse the settings
let settings: MyConfig = scuffle_settings::parse_settings(options)?;
See Options for more information on how to customize parsing.
If the templates feature is enabled, the parser will attempt to render
the configuration file as a jinja template before processing it.
All environment variables set during execution will be available under
the env variable inside the file.
Example TOML file:
some_setting = "${{ env.MY_APP_SECRET }}"
Use ${{ and }} for variables, {% and %} for blocks and {# and #} for comments.
The following options are available for the CLI:
--config or -c
Path to a configuration file. This option can be used multiple times to load multiple files.
--override or -o
Provide an override for a configuration value, in the format KEY=VALUE.
This project is licensed under the MIT or Apache-2.0 license. You can choose between one of them if you use this work.
SPDX-License-Identifier: MIT OR Apache-2.0