Salak.rs
A multi layered configuration loader and zero-boilerplate configuration parser.
Install / Use
/learn @leptonyu/Salak.rsREADME
salak involve too many stuffs and confused names not only config, please use cfg-rs instead.
Salak is a multi layered configuration loader and zero-boilerplate configuration parser, with many predefined sources.
Please refer to salak doc.
Notice
Please notice that salak-0.9.* is totally rewrited, so the APIs may changes much, and some functions may be removed. They will be added in later version.
Quick Example
use salak::*;
#[derive(Debug, FromEnvironment)]
#[salak(prefix = "config")]
struct Config {
#[salak(default = false)]
verbose: bool,
optional: Option<String>,
#[salak(name = "val")]
value: i64,
}
let env = Salak::builder()
.set("config.val", "2021")
.build()
.unwrap();
let config = env.get::<Config>().unwrap();
assert_eq!(2021, config.value);
assert_eq!(None, config.optional);
assert_eq!(false, config.verbose);
Trait FromEnvironment
Salak Factory
salak_factory can initialize resource based on salak, such as redis, postgresql, etc.
use std::sync::Arc;
use salak::*;
use salak_factory::redis_default::RedisPool;
generate_service!(RedisService {
redis: RedisPool,
#[salak(namespace = "hello", access = "pub")]
back: Option<RedisPool>
});
fn main() -> Result<(), PropertyError> {
env_logger::builder()
.filter_level(log::LevelFilter::Info)
.try_init()?;
let env = Salak::builder()
.register_default_resource::<RedisPool>()?
.configure_args(app_info!())
.build()?;
let _service = env.get_service::<RedisService>()?;
let _conn = _service.as_redis().get()?;
Ok(())
}
Related Skills
himalaya
347.0kCLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
taskflow
347.0kname: taskflow description: Use when work should span one or more detached tasks but still behave like one job with a single owner context. TaskFlow is the durable flow substrate under authoring layer
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
